【发布时间】:2015-09-01 21:43:21
【问题描述】:
我有一个使用 Selenium 和 PhantomJS 的小型测试 python 脚本。 Python 版本是 2.7,PhantomJS 是 1.9.2。稍后我计划将其与 BeautifulSoup 一起用于访问金融网站。
我的 python 脚本是这样的 -
from selenium import webdriver
phantomJSPath = "C:\my working dir\\Lib\phantomjs.exe"
browser = webdriver.PhantomJS(executable_path=phantomJSPath)
执行后我得到以下错误 -
文件“C:\my working dir\Test.py”,第 32 行,运行中
browser = webdriver.PhantomJS(executable_path=phantomJSPath)
File "C:\Python27\lib\site- packages\selenium\webdriver\phantomjs\webdriver.py", line 56, in __init__
desired_capabilities=desired_capabilities)
File "C:\Python27\lib\site- packages\selenium\webdriver\remote\webdriver.py", line 87, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 136, in start_session
'desiredCapabilities': desired_capabilities,
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 196, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 102, in check_response
value = json.loads(value_json)
File "C:\Python27\lib\json\__init__.py", line 326, in loads
return _default_decoder.decode(s)
File "C:\Python27\lib\json\decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python27\lib\json\decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
有人知道我为什么会收到这个错误吗?
【问题讨论】:
-
PhantomJS 1.9.2 真的很旧,可能存在与 GhostDriver 和 selenium 库不兼容的问题。尝试更新到更新的 PhantomJS 版本,例如 2.0.0、1.9.8 或 1.9.7。
-
您使用的是哪个版本的 Selenium?