![](/img/trans.png)
[英]selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service error using ChromeDriver Chrome through Selenium Python
[英]Selenium and Python3 ChromeDriver raises Message: Can not connect to the Service chromedriver
请问如何让硒在这个场景中工作? 我已经看到这些问题的答案很少或没有答案,我希望今天运气站在我这边。
让我从详细介绍我的环境开始。
我在python3 中使用virtualenv/virtualenvwrapper来运行以下命令。
from selenium import webdriver from selenium.webdriver.common.keys import Keys import os chromedriver = "/usr/local/bin/chromedriver" os.environ["webdriver.chrome.driver"] = chromedriver driver = webdriver.Chrome() driver.get("http://www.python.org") print(driver.title) driver.quit()
在我遵循类似问题here的示例之后添加了以下行
chromedriver = "/usr/local/bin/chromedriver" # i used brew to install chrome to get this path from the command 'which chromedriver'
os.environ["webdriver.chrome.driver"] = chromedriver
或者我直接从github下载了chromedriver并添加了如下路径:
/用户/我/下载/ chromedriver
我已经尝试过没有将争论传递给驱动程序,但我仍然收到此错误。
Traceback (most recent call last):
File "aicpa.py", line 8, in <module>
driver = webdriver.Chrome()
File "/Users/Me/.virtualenvs/aicpa/lib/python3.5/site-packages/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
self.service.start()
File "/Users/Me/.virtualenvs/aicpa/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 102, in start
raise WebDriverException("Can not connect to the Service %s" % self.path)
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver
本赛季的补充,并提前致谢。
你试过这个吗?
webdriver.Chrome("/usr/local/bin/chromedriver")
我没有测试这个,但请尝试:
chromedriver = "/usr/local/bin"
os.environ[] 只是添加了一个路径变量,它必须是一个文件夹而不是一个文件。
在我的情况下,将127.0.0.1 localhost
添加到hosts
文件解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.