Python Selenium ChromeDriver 不可访问

3

我无法弄清为什么会出现这个异常。当我单独运行chromedriver时,我得到以下结果:

Starting ChromeDriver 2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3) on port 9515

但是当我尝试从文件中运行它时,我得到以下结果:

WebDriverException: Message: chrome not reachable (Driver info: chromedriver=2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3),platform=Linux 3.13.0-52-generic x86_64)

代码:

if self.proxy:
    chrome_options = Options()
    chrome_options.add_argument("--proxy-server=http://user:password@proxy.com:8080")
    self.webdriver = webdriver.Chrome('/usr/bin/google-chrome', chrome_options=chrome_options)
else:
    self.webdriver = webdriver.Chrome('/usr/bin/google-chrome')

我正在不使用代理的情况下运行它。如果我不提供路径,由于某种原因它将无法找到Chrome二进制文件。不确定我接下来该怎么做。

2个回答

0

下载Chrome驱动程序并使用此代码

driver = webdriver.Chrome("C:\\chromedriver.exe")

0

你需要在第一个位置参数或executable_path关键字参数中指定的路径是chromedriver的路径,而不是chrome本身的路径:

self.webdriver = webdriver.Chrome('/path/to/chromedriver', chrome_options=chrome_options)

如果 chromedriver$PATH 中 - 你根本不需要指定路径 - 这通常是情况。

嗯,有道理。我的路径出了一些问题。我已经修复了它,现在甚至不需要指定路径就能启动它。但是很遗憾,我仍然会得到相同的错误(无论我是否指定路径)。 - user3084860
@user3084860,是的,你说得对,“chrome not reachable”与其他问题有关。根据我搜索到的信息,有很多原因。你能否检查一下,使用self.webdriver = webdriver.Chrome()实例化Chrome是否会出现相同的错误?谢谢。 - alecxe

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接