How to install PhantomJS for use with Python Selenium on the Raspberry Pi? How to install PhantomJS for use with Python Selenium on the Raspberry Pi? linux linux

How to install PhantomJS for use with Python Selenium on the Raspberry Pi?


Ok I will start with the solution, there is a version compiled for arm here phantomjs-linux-armv6l, on the pi run the following commands:

$ 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

So phantomjs will be on your path.

pi@raspberrypi ~ $ phantomjs --version1.9.0pi@raspberrypi ~ $ phantomjsphantomjs> 

Now we have that done, time to test:

pi@raspberrypi ~ $ cat test.py#!/usr/bin/pythonfrom selenium import webdriverdriver = 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")>

From the faq. Starting with PhantomJS 1.5, it is pure headless and there is no need to run X11/Xvfb anymore..

I tried using xvfb-run and exporting the display, using a shell script in init.d to start xvfb, I got a little further being able to run iceweasel from bash headless no problem but still no cigar when it came to phantomjs and selenium. I think it may just come down to an incompatibility between selenium and the version of phantomjs, regardless having 1.9.0 and real headless browsing is a lot more desirable.

I was in the middle of setting up a toolchain and was going to try to compile myself when I found the link above, for anyone interested in cross compiling, crosstools-ng makes life a lot easier.

I am running an arm6, there is also a compiled version for arm7 using 2.0.0, the dependencies are:

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

The install procedure, I have extracted the binary to dropbox:

wget https://www.dropbox.com/s/epj1rji9d239dco/phantomjschmod +x phantomjssudo cp phantomjs /usr/bin

The original github link is phantomjs-2.0.0-armv7


Here's how I did it :

For 64-bit system, download phantomjs-1.9.7-linux-x86_64.tar.bz2 (12.6 MB).For 32-bit system, download phantomjs-1.9.7-linux-i686.tar.bz2 (12.9 MB).Step 1> $ wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2Step 2> $ tar -xvf phantomjs-1.9.7-linux-x86_64.tar.bz2Step 3> $ cd phantomjs-1.9.7-linux-x86_64Step 4> $ cd binStep 5> $ sudo cp phantomjs /usr/binTo check phantomjs installed properly perform the following step : Step 6> $ phantomjs -hTo install the dependencies on Red Hat based systems:Step 7> $ sudo yum install fontconfig freetype libfreetype.so.6 libfontconfig.so.1 libstdc++.so.6


Download this phantomjs file https://drive.google.com/open?id=1x063Krw6mZkRYW4K238a3EyRdklj5Evj

Replace to needed folder.

Give 777 chmod:chmod 777 phantomjs

And try to use.

For Grafana - phantomjs file must be in a folder: /usr/share/grafana/tools/phantomjs/.

This binary file work to me on Banana pi M3 Debian 9. Architecture: arm armv7l. Kernel 4.20.7-sunxi