欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Python3 + selenium + Chrome浏览器(webdriver.Chrome()报错)

程序员文章站 2022-08-03 19:01:39
Python3 + selenium + Chrome浏览器 Error: selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.Please see ......


python3 + selenium + chrome浏览器

error:
  selenium.common.exceptions.webdriverexception: message: 'chromedriver' executable needs to be in path.please see https://sites.google.com/a/chromium.org/chromedriver/home

这是因为调用 webdriver.chrome() 需要设置参数 executable_path,而executable_path 为chromedriver.exe所在地址。

chromedriver.exe的下载地址为 http://chromedriver.storage.googleapis.com/index.html

首先需要确定本机的chrome浏览器的版本,在chrome浏览器里输入"chrome://version"即可,如下图,google chrome冒号后面即为对应版本。本机的chrome版本为75.0.3770.142,下载地址中并无完全吻合的版本,最后下载了75.0.3770.142版本对应的亦可兼容本机。

Python3 + selenium + Chrome浏览器(webdriver.Chrome()报错)

这是下载地址界面:

Python3 + selenium + Chrome浏览器(webdriver.Chrome()报错)

然后我们转到对应版本界面,选择对应系统的zip文件下载并解压。

Python3 + selenium + Chrome浏览器(webdriver.Chrome()报错)

得到chromedriver.exe文件后,给 webdriver.chrome() 添加参数 executable_path = 'path/chromedriver.exe'(path为chromedriver.exe所在的目录)

之后我的代码就运行成功了

Python3 + selenium + Chrome浏览器(webdriver.Chrome()报错)