首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Selenium无法连接到GhostDriver (但有时)

Selenium无法连接到GhostDriver (但有时)
EN

Stack Overflow用户
提问于 2014-07-04 17:38:32
回答 1查看 6.4K关注 0票数 9

我在Python / Selenium和PhantomJS中设置了一个简单的webscraping脚本。我总共有200个网址要刮。脚本一开始运行良好,然后在大约20-30个URL之后运行(当它失败时,它看起来可能是随机的,并且与任何特定的URL无关),我在python中得到了以下错误:

代码语言:javascript
复制
selenium.common.exceptions.WebDriverException: Message: 'Can not connect to GhostDriver'

我的ghostdriver.log:

代码语言:javascript
复制
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

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-04 20:09:00

为了修复它,我遇到了同样的问题--,我从源安装了幻影。

代码语言:javascript
复制
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

代码语言:javascript
复制
Optional :
cd bin
chmod +x phantomjs
cp phantomjs /usr/bin/

我搞清楚了,因为当我读我的ghostdriver.log文件时,上面写着。

代码语言:javascript
复制
[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}]}

我确信一定有一些丢失的文件,它肯定是用来处理一些边缘情况的。所以我决定从源头开始建造,现在它的工作还不错。

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24578879

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档