我在Python / Selenium和PhantomJS中设置了一个简单的webscraping脚本。我总共有200个网址要刮。脚本一开始运行良好,然后在大约20-30个URL之后运行(当它失败时,它看起来可能是随机的,并且与任何特定的URL无关),我在python中得到了以下错误:
selenium.common.exceptions.WebDriverException: Message: 'Can not connect to GhostDriver'我的ghostdriver.log:
PhantomJS is launching GhostDriver...
[ERROR - 2014-07-04T17:27:37.519Z] GhostDriver - main.fail - {"message":"Could not start Ghost Driver","line":82,"sourceId":140692115795456,"sourceURL":":/ghostdriver/main.js","stack":"Error: Could not start Ghost Driver\n at :/ghostdriver/main.js:82","stackArray":[{"sourceURL":":/ghostdriver/main.js","line":82}]}我已经搜索过了,上面的大部分问题似乎都无法运行一个URL。我发现错误发生在脚本中间的唯一其他问题是this one,答案是将幻影升级到最新版本,我已经这样做了。另一个答案只是说再次尝试这个URL,这似乎不是一个很好的解决方案,因为URL可能会再次失败。
我在python 2.7.6上运行Linux 17上的幻影版本1.9.7和selenium版本2.42.1
for url in ['example.com/1/', 'example.com/2/', 'example.com/3/', .. , ..]:
user_agent = 'Chrome'
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap['phantomjs.page.settings.userAgent'] = user_agent
driver = webdriver.PhantomJS(executable_path='/usr/bin/phantomjs', desired_capabilities=dcap)
driver.get(url)发布于 2014-09-04 20:09:00
为了修复它,我遇到了同样的问题--,我从源安装了幻影。
For Linux (Debian):
sudo apt-get update
sudo apt-get install build-essential chrpath git-core libssl-dev libfontconfig1-dev libxft-dev
git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout 1.9
./build.sh
For Mac os:
git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout 1.9
./build.sh对于其他系统,请检查以下链接http://phantomjs.org/build.html
Optional :
cd bin
chmod +x phantomjs
cp phantomjs /usr/bin/我搞清楚了,因为当我读我的ghostdriver.log文件时,上面写着。
[ERROR - 2014-09-04T19:33:30.842Z] GhostDriver - main.fail - {"message":"Could not start Ghost Driver","line":82,"sourceId":140145669488128,"sourceURL":":/ghostdriver/main.js","stack":"Error: Could not start Ghost Driver\n at :/ghostdriver/main.js:82","stackArray":[{"sourceURL":":/ghostdriver/main.js","line":82}]}我确信一定有一些丢失的文件,它肯定是用来处理一些边缘情况的。所以我决定从源头开始建造,现在它的工作还不错。
https://stackoverflow.com/questions/24578879
复制相似问题