【发布时间】:2017-06-17 11:54:28
【问题描述】:
只是一个简单的 Python 代码:
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--user-agent={}".format(config.USER_AGENT))
driver = webdriver.Chrome("/usr/local/bin/chromedriver",
chrome_options=chrome_options)
还有 chromedriver:
$ ls /usr/local/bin/chromedriver
/usr/local/bin/chromedriver
还有:
$ chromedriver
Starting ChromeDriver 2.29 on port 9515
Only local connections are allowed.
但是当我运行 python 脚本时,它会抛出无法连接到 chromedriver 的异常:
Traceback (most recent call last):
File "main.py", line 98, in <module>
driver = webdriver.Chrome("/usr/local/bin/chromedriver", chrome_options=chrome_options)
File "/home/me123/.local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
self.service.start()
File "/home/me123/.local/lib/python3.6/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 /usr/local/bin/chromedriver
如何解决?
【问题讨论】:
-
只是一个想法。可以重启试试吗?
标签: python linux python-3.x selenium selenium-chromedriver