WebDriverException:未知错误:对于旧版本的 Google Chrome,无法在 Python 中找到带有 Selenium 的 Chrome 二进制错误

2023-12-26

出于兼容性原因,我更喜欢使用 Chrome 版本 55.0.2883.75 和 Chromedriver v. 2.26。我从以下位置下载了旧版本的 Chromehttps://www.slimjet.com/chrome/google-chrome-old-version.php https://www.slimjet.com/chrome/google-chrome-old-version.php和 Chromedriver 2.26 来自https://chromedriver.storage.googleapis.com/index.html?path=2.26/ https://chromedriver.storage.googleapis.com/index.html?path=2.26/.

我正在使用以下代码尝试设置我的 Chrome 二进制位置:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.binary_location = "C:\\Program Files\\Chrome\\chrome64_55.0.2883.75\\chrome.exe"
driver = webdriver.Chrome('chromedriver.exe', chrome_options = options)

但是,当我尝试启动 WebDriver Python 时返回以下错误:

WebDriverException: unknown error: cannot find Chrome binary
(Driver info: chromedriver=2.26.436362
(5476ec6bf7ccbada1734a0cdec7d570bb042aa30),platform=Windows NT 10.0.14393 x86_64)

我曾尝试搜索类似的问题和答案,但到目前为止还没有任何运气。


这个错误信息...

WebDriverException: unknown error: cannot find Chrome binary

...意味着Chrome驱动程序无法找到Chrome二进制文件位于系统的默认位置。

根据ChromeDriver - 要求 https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver/01fde32d0ed245141e24151f83b7c2db31d596a4#requirements:

服务器希望您将 Chrome 安装在每个系统的默认位置:

OS Expected Location of Chrome
Linux /usr/bin/google-chrome1
Mac /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
Windows XP %HOMEPATH%\Local Settings\Application Data\Google\Chrome\Application\chrome.exe
Windows Vista and newer C:\Users%USERNAME%\AppData\Local\Google\Chrome\Application\chrome.exe

1 For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary.


在非标准位置使用 Chrome 可执行文件

但是您也可以覆盖默认值Chrome 二进制文件位置如下:

To use Chrome 版本 55.x通过安装在非标准位置Chrome 驱动程序 v2.26您可以使用以下代码:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.binary_location = "C:\\Program Files\\Chrome\\chrome64_55.0.2883.75\\chrome.exe"
driver = webdriver.Chrome(chrome_options = options, executable_path=r'C:\path\to\chromedriver.exe')
driver.get('http://google.com/')
print("Chrome Browser Invoked")
driver.quit()

相关文档 https://sites.google.com/a/chromium.org/chromedriver/capabilities#TOC-Using-a-Chrome-executable-in-a-non-standard-location


参考

您可以在以下位置找到详细讨论:

  • 使用 Selenium 时是否需要安装 Chrome 还是只安装 chromedriver? https://stackoverflow.com/questions/53330322/is-chrome-installation-needed-or-only-chromedriver-when-using-selenium/62449076#62449076
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

WebDriverException:未知错误:对于旧版本的 Google Chrome,无法在 Python 中找到带有 Selenium 的 Chrome 二进制错误 的相关文章

随机推荐