好的,我将从解决方案开始,这里有一个为arm编译的版本phantomjs-linux-armv6l https://github.com/aeberhardo/phantomjs-linux-armv6l,在 pi 上运行以下命令:
$ cd /tmp
$ wget https://github.com/aeberhardo/phantomjs-linux-armv6l/archive/master.zip
$ unzip master.zip
$ cd phantomjs-linux-armv6l-master
$ bunzip2 *.bz2 && tar xf *.tar
I added:
sudo cp phantomjs-1.9.0-linux-armv6l/bin/phantomjs /usr/bin
所以 phantomjs 将在你的道路上。
pi@raspberrypi ~ $ phantomjs --version
1.9.0
pi@raspberrypi ~ $ phantomjs
phantomjs>
现在我们已经完成了,是时候测试了:
pi@raspberrypi ~ $ cat test.py
#!/usr/bin/python
from selenium import webdriver
driver = webdriver.PhantomJS()
driver.get('http://stackoverflow.com/questions/36314771/how-to-install-phantomjs-for-use-with-python-selenium-on-the-raspberry-pi/36388824#36388824')
a = driver.find_element_by_xpath('//*[@id="question-header"]/h1/a')
print(a.text)
print(driver)
pi@raspberrypi ~ $ python test.py
How to install PhantomJS for use with Python Selenium on the Raspberry Pi?
<selenium.webdriver.phantomjs.webdriver.WebDriver (session="b184e110-f9c4-11e5-aede-7f5c42f062d7")>
来自faq http://phantomjs.org/faq.html. 从 PhantomJS 1.5 开始,它是纯粹的无头,不再需要运行 X11/Xvfb。.
我尝试使用xvfb-run并导出显示,使用 init.d 中的 shell 脚本启动 xvfb,我进一步能够从 bash headless 运行iceweasel,没问题,但在 phantomjs 和 selenium 方面仍然没有雪茄。我认为这可能归结为 selenium 和 phantomjs 版本之间的不兼容,无论拥有 1.9.0 并且真正的无头浏览更可取。
当我发现上面的链接时,我正在设置一个工具链,并打算尝试自己编译,对于任何对交叉编译感兴趣的人,交叉工具-ng http://crosstool-ng.org/让生活变得更加轻松。
我运行的是arm6,还有一个编译版本 https://github.com/hikomat/phantomjs-2.1.1-armv7对于使用2.0.0的arm7,依赖项是:
sudo apt-get install flex bison gperf ruby perl libsqlite3-dev libfontconfig1-dev libicu-dev libfreetype6 libssl-dev libpng-dev libjpeg-dev python libX11-dev libxext-dev
安装过程中,我已将二进制文件提取到 dropbox:
wget https://www.dropbox.com/s/epj1rji9d239dco/phantomjs
chmod +x phantomjs
sudo cp phantomjs /usr/bin
原来的github链接是phantomjs-2.0.0-armv7 https://github.com/hikomat/phantomjs-2.1.1-armv7