简体   繁体   English

Python Selenium ChromeDriver 无法访问

[英]Python Selenium ChromeDriver Not Reachable

So I'm unable to figure out why I am getting this exception.所以我无法弄清楚为什么我会得到这个异常。 When I run the chromedriver alone I get:当我单独运行 chromedriver 时,我得到:

Starting ChromeDriver 2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3) on port 9515在端口 9515 上启动 ChromeDriver 2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3)

When I try to run it from a file I get:当我尝试从文件运行它时,我得到:

WebDriverException: Message: chrome not reachable (Driver info: chromedriver=2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3),platform=Linux 3.13.0-52-generic x86_64) WebDriverException:消息:chrome 无法访问(驱动程序信息:chromedriver=2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3),platform=Linux 3.13.0-52-generic x86_64)

The code:编码:

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

I'm running it without the proxy.我在没有代理的情况下运行它。 If I don't supply the path, for some reason it won't be able to find the chrome binary.如果我不提供路径,由于某种原因它将无法找到 chrome 二进制文件。 Not sure where I should go from here.不知道我应该从这里去哪里。

The path you need to specify in the first positional or executable_path keyword argument is a path to the chromedriver, not the chrome itself :您需要在第一个 positional 或executable_path关键字参数中指定的路径是 chromedriver 的路径,而不是 chrome 本身

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

If chromedriver is in $PATH - you don't need to specify the path at all - this is usually the case.如果chromedriver$PATH - 您根本不需要指定路径 - 通常是这种情况。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM