「Selenium」- Can not connect to the Service /path/to/chromedriver @20210211

在尝试使用Python的Selenium库运行Chrome浏览器时遇到了'Cannot connect to the Service'错误,具体为'selenium.common.exceptions.WebDriverException'。问题根源在于ChromeDriver与Selenium之间的连接失败。解决方案是将127.0.1.1 localhost添加到/etc/hosts文件中。确保ChromeDriver的路径正确无误,并且与Selenium版本匹配。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题描述

# python3.7 /tmp/demo.py
Traceback (most recent call last):
  File "/tmp/demo.py", line 4, in <module>
    driver = webdriver.Chrome('/srv/sharing/packages/chromedriver_linux64/chromedriver')  # Optional argument, if not specified will search path.
  File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
    self.service.start()
  File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/common/service.py", line 104, in start
    raise WebDriverException("Can not connect to the Service %s" % self.path)
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service /srv/sharing/packages/chromedriver_linux64/chromedriver

问题原因

Selenium python: Can not connect to the Service %s" % self.path
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service geckodriver

解决办法

添加 127.0.1.1 localhost 到 /etc/hosts 文件。

相关文章

「Selenium Grid 3」- Node xxxxx has no free slots(close() vs quit())
「Selemium」- ChromeDriver only supports characters in the BMP

参考文献

Selenium python: Can not connect to the Service %s" % self.path
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service geckodriver

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值