对于旧版本的Google Chrom,在Python中找不到带有Selenium的Chrome二进制文件

2024-04-25 09:39:40 发布

您现在位置:Python中文网/ 问答频道 /正文

出于兼容性的原因,我更喜欢使用Chrome版本55.0.2883.75和Chromedriver v.2.26。我从https://www.slimjet.com/chrome/google-chrome-old-version.php下载了chrome的旧版本,从https://chromedriver.storage.googleapis.com/index.html?path=2.26/下载了Chromedriver 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)

我试过寻找类似的问题和答案,但至今没有任何运气。非常感谢您的帮助-提前谢谢!


Tags: fromhttpsimportcomselenium原因chromeexe
2条回答

检查https://sites.google.com/a/chromium.org/chromedriver/getting-started 可以在webdriver的构造函数中指定二进制路径:

driver = webdriver.Chrome('/path/to/chromedriver')  # Optional argument, if not specified will search path.

此错误消息。。。

WebDriverException: unknown error: cannot find Chrome binary

…表示ChromeDriver无法在系统的默认位置找到Chrome二进制文件。

根据ChromeDriver - Requirements

The ChromeDriver server expects you to have Chrome installed in the default location for each system as follows:

ChromeLocation

1对于Linux系统,ChromeDriver期望/usr/bin/google-chrome是一个符号链接到实际的Chrome二进制


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

但是,您也可以覆盖默认的Chrome二进制位置,如下所示:

Chrome_non_standard_location


要使用通过ChromeDriver v2.26安装在非标准位置的Chrome 55.x版,可以使用以下代码块:

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()

相关问题 更多 >

    热门问题