[問題] selenium phantomjs Unicode error

看板Python作者 (coyote)時間8年前 (2017/04/07 17:02), 8年前編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/1
最近因為有些網站用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://www.ptt.cc/bbs/Python/M.1491555751.A.0BC.html

04/07 20:36, , 1F
環境變數有設好嗎?
04/07 20:36, 1F
有設環境變數 前幾天有成功執行過 cmd也可直接輸入phantomjs運行phantomjs ※ 編輯: karta0910489 (140.118.71.16), 04/07/2017 21:45:09
文章代碼(AID): #1OvrMd2y (Python)
文章代碼(AID): #1OvrMd2y (Python)