Python 为什么当前的“url提高”;无法解码任何JSON对象";w/硒及;Ubuntu 16.04上的PhantomJS?
这是报告:Python 为什么当前的“url提高”;无法解码任何JSON对象";w/硒及;Ubuntu 16.04上的PhantomJS?,python,linux,selenium,ubuntu,phantomjs,Python,Linux,Selenium,Ubuntu,Phantomjs,这是报告: sudo apt install phantomjs export QT_QPA_PLATFORM=offscreen python >>> import selenium.webdriver >>> from selenium.webdriver.common.desired_capabilities import DesiredCapabilities >>> browser = selenium.webdriver.Phan
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
看来
phantomjs
包只是坏了(缺少组件)。有一些解决方案使用了npm
,但因为我在使用Python,所以我想避免这种情况。下面是我最后为解决这个问题所做的:
unset QT_QPA_PLATFORM
sudo apt purge phantomjs
wget -q https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
tar xvjf phantomjs-2.1.1-linux-x86_64.tar.bz2
sudo mv phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/
我的其他二进制文件在
/usr/local/bin
中,但是如果将它们放在/usr/bin
中,它也可以工作。看来phantomjs
包只是坏了(缺少组件)。有一些解决方案使用了npm
,但因为我在使用Python,所以我想避免这种情况。下面是我最后为解决这个问题所做的:
unset QT_QPA_PLATFORM
sudo apt purge phantomjs
wget -q https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
tar xvjf phantomjs-2.1.1-linux-x86_64.tar.bz2
sudo mv phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/
我的其他二进制文件位于/usr/local/bin
中,但是如果您将它们置于/usr/bin
中,它也可以工作