Selenium python+chrome/firefox報錯Message: Can not connect to the Service chromedriver


1、執行

>>> from selenium.webdriver import Chrome

#添加path后執行

>>> driver = Chrome()

或>>> from selenium.webdriver import Chrome

#驅動位置驅動

>>> Chrome(executable_path='/usr/local/bin/chromedriver')

報錯:

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "/Users/cdtanghui3/Library/Python/2.7/lib/python/site-packages/selenium/webdriver/chrome/webdriver.py", line 62, in __init__

    self.service.start()

  File "/Users/cdtanghui3/Library/Python/2.7/lib/python/site-packages/selenium/webdriver/common/service.py", line 92, 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

解決辦法:加hosts:127.0.0.1 localhost

$ vi /etc/hosts

添加127.0.0.1 localhosts

執行:

>>> from selenium.webdriver import Chrome

>>> Chrome(executable_path='/usr/local/bin/chromedriver')

打開chrome瀏覽器成功


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM