作者karta0910489 (coyote)
看板Python
标题[问题] selenium phantomjs Unicode error
时间Fri Apr 7 17:02:28 2017
最近因为有些网站用JS产生资讯
所以开始学习使用动态爬虫
使用python3.5.2 + selenium(3.3.3) + phantomjs(2.1.1)
from selenium import webdriver
driver = webdriver.PhantomJS()
driver.get("
https://www.google.com.tw/")
source = driver.page_source
print(source)
在driver=webdriver.PhantomJS()会产生错误
Traceback (most recent call last):
File "C:\Users\name\Desktop\crawlertest.py", line 16, in <module>
driver = webdriver.PhantomJS()
File
"C:\Users\name\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\phantomjs\webdriver.py",
line 58, in __init__
desired_capabilities=desired_capabilities)
File
"C:\Users\name\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py",
line 98, in __init__
self.start_session(desired_capabilities, browser_profile)
File
"C:\Users\name\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py",
line 185, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File
"C:\Users\name\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py",
line 247, in execute
response = self.command_executor.execute(driver_command, params)
File
"C:\Users\name\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\remote_connection.py",
line 464, in execute
return self._request(command_info[0], url, body=data)
File
"C:\Users\name\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\remote_connection.py",
line 537, in _request
body = data.decode('utf-8').replace('\x00', '').strip()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbf in position 189:
invalid start byte
前几天运行都还没问题 可是昨天跟今天突然开始运行失败
如果放到虚拟机Ubuntu也都可以顺利运行
想问一下该怎麽解决这个问题
感谢
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.118.71.16
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1491555751.A.0BC.html
1F:推 Steven87: 环境变数有设好吗? 04/07 20:36
有设环境变数 前几天有成功执行过 cmd也可直接输入phantomjs运行phantomjs
※ 编辑: karta0910489 (140.118.71.16), 04/07/2017 21:45:09