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