selenium+phantomjs报错raise WebDriverException(“Can not connect to the Service %s“ % self.path)

报错:

raise WebDriverException("Can not connect to the Service %s" % self.path)
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service .../phantomjs-2.1.1-linux-x86_64/bin/phantomjs

代码:

from selenium import webdriver

driver = webdriver.PhantomJS(executable_path="/var/server/python/my_project/phantomjs-2.1.1-linux-x86_64/bin/phantomjs", service_args=["--load-images=no"])
driver.get(url="file:var/server/python/my_project/xxx.html")  # 本地网页

系统/etc/hosts文件:

127.0.0.1   mirror

::1   mirror

127.0.0.1   localhost  # 加上此行解决问题

问题:

应该算系统dns解析问题,深入了解/etc/hosts文件的作用...

在需要访问localhost(默认主机名称)的时候特别需要注意,最好可以直接访问127.0.0.1(未做尝试,不知道从哪控制访问,有大佬知道指点一二)

解决:

好吧,我能够重现这个问题,随后修复了它。不知道这是否是每个人都会遇到的问题,但这里是这样的:

根据直觉,我把 127.0.0.1   localhost 从我的/etc/hosts文件中删掉。然后我就能重现这个问题,就像这里描述的那样。

之后,我又把这行加了回去,Selenium又开始工作了,包括Chromedriver和Geckodriver。

参考资料:

selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service geckodriver #2903

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值