python使用selenium调用chrome浏览器操作

1、

先安装selenium

pip install selenium

2、

使用WebDriver在Chrome浏览器上进行测试时,需要从 http://chromedriver.storage.googleapis.com/index.html 网址中下载与本机chrome浏览器对应的驱动程序,驱动程序名为chromedriver;

chromedriver的版本需要和本机的chrome浏览器对应,才能正常使用;
本机的版本在chrome的安装路径中查看
python使用selenium调用chrome浏览器操作
我的版本为71.0.3578

找上述网址找到对应版本后下载win版本。
python使用selenium调用chrome浏览器操作

3、

把文件解压到chrome的安装路径中
python使用selenium调用chrome浏览器操作

使用方法:

如果你不想给chromedriver.exe配置环境变量的话,就直接加上绝对路径

from selenium import webdriver
 
browser = webdriver.Chrome('E:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe')
browser.get('http://www.baidu.com/')