只是一个简单的代码在Python:的Python库的webdriver不获取连接到chromedriver - “无法连接到服务的/ usr/local/bin目录/ chromedriver”
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脚本,它抛出一个异常,它是无法连接到CHR omedriver:
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
如何解决?
只是一个想法。你可以重新启动并尝试吗? –