我想在运行Raspbian的_2856771上使用 Selenium WebDriver
和 PhantomJS
作为无头浏览器运行Python脚本 .
我最初在OS X中编写了脚本,它可以正常工作 . 但是为了让它在Raspberry上运行,我遇到了问题 .
尝试运行脚本时,我收到此错误:
raise WebDriverException("Can not connect to the Service %s" % self.path)
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service /usr/bin/phantomjs
脚本的简要版本:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
user_agent = ("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) " +
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36")
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = user_agent
serv_args = ["--ignore-ssl-errors=false", "--ssl-protocol=tlsv1",
"--disk-cache=false"]
driver = webdriver.PhantomJS(executable_path="/usr/bin/phantomjs",
desired_capabilities = dcap, service_arguments = serv_args, port=65000)
我看到其他人有类似我的问题 - 有不同的解决方案 - 大多数似乎都涉及自己构建PhantomJS,或克隆并安装适用于Raspberry的Github分支(现在与主要的PhantomJS项目不同步) .
问题
-
有谁知道如何解决问题 - 事实上问题究竟是什么?
-
如果解决方案涉及手动将二进制文件安装到
/usr/local/bin
等,我该怎么做? PhantomJS webpage上可用的二进制文件用于linux-x86
和linux-i686
,因此我在Raspberry Pi 2 B ARM Cortex A-7处理器上工作 . -
我也试图根据这些instructions自己建造PhantomJS,但是这个过程在中途冻结了 . Raspberry也不符合建议的硬件要求 .
背景信息
-
我正在使用
Python 2.7.9
-
我创建了
virtualenv
并在其中安装了所有Python模块;例如pip install selenium
,并尝试在此处运行脚本 -
我已通过
sudo apt-get install phantomjs
安装了最新版本的PhantomJS -
我在测试时禁用了我的
ufw
防火墙
3 回答
好的我将从解决方案开始,有一个为arm编译的版本phantomjs-linux-armv6l,在pi运行以下命令:
我补充说:
所以phantomjs将在你的道路上 .
现在我们已经完成了,有时间测试:
来自faq . 从PhantomJS 1.5开始,它是纯无头的,不再需要运行X11 / Xvfb了 .
我尝试使用xvfb-run并导出显示,在init.d中使用shell脚本启动xvfb,我进一步能够从bash运行iceweasel无头没有问题,但是当它来到phantomjs和selenium时仍然没有雪茄 . 我认为它可能只是归结为selenium和phantomjs版本之间的不兼容性,无论是1.9.0还是真正的无头浏览都是非常可取的 .
我正在设置一个工具链,当我找到上面的链接时,我会尝试编译自己,对于任何对交叉编译感兴趣的人,crosstools-ng让生活变得更轻松 .
我正在运行arm6,还有一个compiled version for arm7使用2.0.0,依赖项是:
安装过程,我已将二进制文件解压缩到dropbox:
原始的github链接是phantomjs-2.0.0-armv7
我是这样做的:
下载此phantomjs文件https://drive.google.com/open?id=1x063Krw6mZkRYW4K238a3EyRdklj5Evj
替换为所需的文件夹 .
给777 chmod:
chmod 777 phantomjs
并尝试使用 .
对于Grafana - phantomjs文件必须位于以下文件夹中:
/usr/share/grafana/tools/phantomjs/
.这个二进制文件在我的Banana pi M3 Debian 9上工作 . 架构:arm armv7l . 内核4.20.7-sunxi