0
這裏的攝製:爲什麼current_url會在Ubuntu 16.04上提升「Selenium&PhantomJS無法解碼JSON對象」?
sudo apt install phantomjs
export QT_QPA_PLATFORM=offscreen
python
>>> import selenium.webdriver
>>> from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
>>> browser = selenium.webdriver.PhantomJS(desired_capabilities=DesiredCapabilities.PHANTOMJS)
>>> browser.get('http://example.com')
>>> browser.title
u'Example Domain'
>>> browser.current_url
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 454, in current_url
return self.execute(Command.GET_CURRENT_URL)['value']
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 201, in execute
self.error_handler.check_response(response)
File "/usr/local/lib.python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 102, in check_response
value = json.loads(value_json)
File "/usr/lib/python2.7/json/__init__.py", line 339, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
注:
- 我在虛擬機上運行安裝所有更新(
sudo apt update
和sudo apt dist-upgrade
已經運行)。 - 此問題似乎也被捕獲爲Ubuntu bug 1569899。我還沒有嘗試修復建議(從tarball構建PhantomJS)。
- 的
QT_QPA_PLATFORM=offscreen
變量是修復錯誤: 「QXcbConnection:無法連接到顯示」(Debian錯誤817277,PhantomJS問題14376)
UPDATE我添加了一個簡單print
捕捉原料響應和這裏的它是什麼:
{'status': 404, 'value': u"Error: - Unable to load Atom 'execute_script' from file ':/ghostdriver/./third_party/webdriver-atoms/execute_script.js'"}