Python+Selenium实现对浏览器的自动操作
实现百度自动搜索
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.Chrome()
url = "http://www.baidu.com"
driver.get(url)
# 设置浏览器窗口大小
driver.set_window_size(1100, 800)
# 获取输入框
driver.find_element_by_id("kw").clear()
# 填入搜索内容
driver.find_element_by_id("kw").send_keys("搜索内容")
# 点击百度一下
driver.find_element_by_id("su").click()
# do something
time.sleep(5)
# 关闭driver 减少内存占用
driver.close()