webdriver调用phantomJS报错

来源:互联网 发布:Apache set cookie 编辑:程序博客网 时间:2024/05/18 22:44

运行Python文件时报错情况如下:
这里写图片描述
raise WebDriverException(“Can not connect to the Service %s” % self.path)
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service phantomjs

  1. 先查看环境变量的路径是否都添加正确,或者程序中指定的路径是否正确
    eg:driver=webdriver.PhantomJS(executable_path=’E:\PhantomJS211\bin\phantomjs.exe’)

  2. 若路径没有问题,则检查hosts文件配置
    2.1 如果更改过初始的hosts文件,则直接将初始hosts文件更改回来就行。因为我以前为了翻墙更改过hosts文件,所以才出现这个问题,解决办法就是直接把hosts文件改回来。
    2.2 以下办法是我在查找解决这个报错问题的时候看到网上的解决方案:
    这里写图片描述

这样重新运行程序,报错就消失啦~

原创粉丝点击