【发布时间】:2017-04-24 04:43:09
【问题描述】:
请问如何让 selenium 在这个场景中工作?我已经多次看到这个问题的答案很少或没有,我希望今天有好运。
让我从详细说明我的环境开始。
- 我正在运行 MacOS Seirra。
-
我正在使用 virtualenv/virtualenvwrapper 和 python3 来运行 关注。
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并添加了如下路径:
/Users/Me/Downloads/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
本季补充,提前致谢。
【问题讨论】:
-
所以你现在有两个 chromedriver 二进制文件,一个在 /usr/local/bin/ 一个在 /Users/Me/Downloads/?由于您启动 Chrome 时没有定义 chromedriver 的路径,因此它将在 PATH 中搜索。也许您没有为文件添加适当的权限?检查它们,这可能是原因。
标签: python macos python-3.x selenium selenium-webdriver