chromedriver下载pip install selenium
chromedriver必须和chrome浏览器的版本一致
复制访问 chrome://version
chrome://version/
chromedriver的下载地址:两个地址
http://chromedriver.storage.googleapis.com/index.html
https://npm.taobao.org/mirrors/chromedriver/
选择对应的版本进行下载,下载完成以后解压,放在python的scripts目录下
复制好 chromedriver.exe的全路径
举例我的是:
pythone代码测试D:PythonPython37scriptschromedriver.exe
# 从selenium导入webdriver模块
from selenium import webdriver
# 导入time模块
import time
# 定义一个函数
def to_baidu():
driver = webdriver.Chrome()
# 窗口最大化
driver.maximize_window()
# get请求目标地址
driver.get('http://www.baidu.com')
# 强制等待5秒,后关闭浏览器
time.sleep(5)
# 关闭浏览器窗口
driver.quit()
# 主方法,启动
if __name__ == '__main__':
# 调用函数
to_baidu()
效果图:自动打开百度
https://www.cnblogs.com/lfri/p/10542797.html



