第一步.查看谷歌版本号
第一种:直接输入
chrome://version/
第二种:
点击Chrome菜单 帮助→关于Google Chrome,查看浏览器版本号
1.下载对应版本驱动
这里用到的是112.0.5615.49的版本谷歌以及该版本的谷歌浏览器。
驱动下载地址:https://chromedriver.storage.googleapis.com/index.html
2.没有使用path变量的情况下。
新建一个selenium.py的测试文件进行测试
from selenium import webdriver
option = webdriver.ChromeOptions()
option.binary_location = r'C:\Program Files\Google\Chrome\Application\chrome.exe'
driver =
webdriver.Chrome(r'C:\ProgramFiles\Google\Chrome\Application\chromedriver.exe')
driver.get("http://www.baidu.com")
3.需要两个变量写入path(使用环境变量的时候)
第一:将谷歌chromedriver存放地址加入path变量里面去。
C:\Program Files\Google\Chrome\Application\chromedriver.exe
---1.可以写在python目录下的Scripts中。
---2.可以写在和谷歌同级别的目录底下。(推荐)
---3.可以放在任意你不会忘记的地方。
记得加入变量里面
---1.测试变量
打开cmd
输入chromedriver,出现
Starting ChromeDriver 112.0.5615.49 (bd2a7bcb881c11e8cfe3078709382934e3916914-refs/branch-heads/5615@{#936}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
就是成功了!
第二步:将谷歌存储二进制exe的目录地址加入path变量里面去
C:\Program Files\Google\Chrome\Application
记得加入变量里面
第三步:新建一个selenium.py的测试文件进行测试
from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.get('https://www.baidu.com')
time.sleep(5)
其他:安装selenium和webdriver
推荐镜像源
pip install selenium -i https://pypi.douban.com/simple
pip install webdriver -i https://pypi.douban.com/simple