问题
So I'm unable to figure out why I am getting this exception. When I run the chromedriver alone I get:
Starting ChromeDriver 2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3) on port 9515
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)
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. Not sure where I should go from here.
回答1:
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:
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.
回答2:
download the chrome driver and use this code
driver = webdriver.Chrome("C:\\chromedriver.exe")
来源:https://stackoverflow.com/questions/30223988/python-selenium-chromedriver-not-reachable