Python 3.x 蟒蛇3+;硒+;幻影独角兽

Python 3.x 蟒蛇3+;硒+;幻影独角兽,python-3.x,selenium,phantomjs,Python 3.x,Selenium,Phantomjs,环境 幻影JS2.1.1;窗口10;硒-3.8.0;蟒蛇3 代码 browser = webdriver.PhantomJS() //throw a UnicodeDecodeError 问题 UnicodeDecodeError:“utf-8”编解码器无法解码位置中的字节0xbd 2:起始字节无效 细节 回溯(最近一次呼叫最后一次): 文件“d:/devtools/phantomjs-2.1.1-windows/bin/IndustryLeaderSpider.py”, 第20行,

环境

幻影JS2.1.1;窗口10;硒-3.8.0;蟒蛇3

  • 代码

    browser = webdriver.PhantomJS() //throw a UnicodeDecodeError   
    
  • 问题

    UnicodeDecodeError:“utf-8”编解码器无法解码位置中的字节0xbd 2:起始字节无效

  • 细节

    回溯(最近一次呼叫最后一次): 文件“d:/devtools/phantomjs-2.1.1-windows/bin/IndustryLeaderSpider.py”, 第20行,在 browser=webdriver.PhantomJS('D:/PhantomJS.exe') 文件“D:\Continuum\Anaconda3\lib\site packages\selenium\webdriver\phantomjs\webdriver.py”, 第58行,在init 期望的_能力=期望的_能力) 文件“D:\Continuum\Anaconda3\lib\site packages\selenium\webdriver\remote\webdriver.py”, 第154行,在init self.start\u会话(所需的\u功能、浏览器\u配置文件) 文件“D:\Continuum\Anaconda3\lib\site packages\selenium\webdriver\remote\webdriver.py”, 第243行,在启动会话中 响应=self.execute(Command.NEW_会话,参数) 文件“D:\Continuum\Anaconda3\lib\site packages\selenium\webdriver\remote\webdriver.py”, 执行中的第309行 响应=self.command\u executor.execute(driver\u command,params) 文件“D:\Continuum\Anaconda3\lib\site packages\selenium\webdriver\remote\remote\u connection.py”, 第460行,执行中 返回self.\u请求(命令信息[0],url,正文=数据) 文件“D:\Continuum\Anaconda3\lib\site packages\selenium\webdriver\remote\remote\u connection.py”, 第522行,输入请求 resp=opener.open(请求,超时=self.\u超时) 文件“D:\Continuum\Anaconda3\lib\urllib\request.py”,第526行,打开 响应=自身打开(请求,数据) 文件“D:\Continuum\Anaconda3\lib\urllib\request.py”,第544行,打开 "开放", 文件“D:\Continuum\Anaconda3\lib\urllib\request.py”,第504行,在调用链中 结果=func(*args) 文件“D:\Continuum\Anaconda3\lib\urllib\request.py”,第806行,在 方法(r、代理、类型)) 文件“D:\Continuum\Anaconda3\lib\urllib\request.py”,第814行,在proxy\u open中 如果请求主机和代理绕过(请求主机): 文件“D:\Continuum\Anaconda3\lib\urllib\request.py”,第2739行,位于代理\u旁路中 返回代理\u旁路\u注册表(主机) 文件“D:\Continuum\Anaconda3\lib\urllib\request.py”,第2706行,位于代理\u旁路\u注册表中 fqdn=socket.getfqdn(rawHost) getfqdn中第673行的文件“D:\Continuum\Anaconda3\lib\socket.py” 主机名、别名、IPADRS=gethostbyaddr(名称) UnicodeDecodeError:“utf-8”编解码器无法解码位置2的字节0xbd:无效的开始字节



  • 有人有这个问题吗?如何修复它?

    您的主要错误似乎是:

    File "D:\Continuum\Anaconda3\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 460, in execute return self._request(command_info[0], url, body=data) File "D:\Continuum\Anaconda3\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 522, in _request resp = opener.open(request, timeout=self._timeout) File "D:\Continuum\Anaconda3\lib\urllib\request.py", line 526, in open response = self._open(req, data)
    
    请尝试以下步骤:

    • 运行
      CCleaner
      工具以清除所有操作系统杂务
    • 重新启动
      系统
    • 启动
      PhantomJS()
      时,提供
      PhantomJS
      二进制文件的绝对路径,如下所示:

      driver = webdriver.PhantomJS(executable_path=r'C:\path\to\phantomjs.exe')
      
    • 确保脚本中没有不必要的
      导入。示例:
      urllib.request

    • 执行
      测试

    你好,谢谢。今天,我的程序运行正常!我只是关闭我的vpn客户端(灯笼),不做任何更改。正如你所说,这也是一个环境问题