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

I want to run a Python script using Selenium WebDriver with PhantomJS as a browser without a browser on my Raspberry Pi working with Raspbian.

I originally wrote a script in OS X where it works great. But trying to get him to work on Raspberry, I have problems.

When I try to run the script, I get this error:

 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 

Short version of the script:

 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) 

I saw that other people have problems similar to mine - with different solutions. Most of them seem to be attracted to the creation of PhantomJS or the cloning and installation of a Github branch adapted for raspberries (which is currently out of sync with the main PhantomJS project).

Questions

  • Does anyone know how to solve a problem - and really, what is the problem really about?
  • If the solution involves manually installing the binaries on /usr/local/bin or something like this, how can I do this? The binaries are available on the PhantomJS webpage for linux-x86 and linux-i686 , so I assume that they will not work on the raspberry Pi 2 B ARM Cortex A-7.
  • I also tried to create PhantomJS myself according to these instructions , but the process froze halfway. Raspberries also do not meet the recommended equipment requirements for the building.

Background Information

  • I am using Python 2.7.9
  • I created virtualenv and installed all the Python modules in it; e.g. pip install selenium and try running the script here
  • I installed the latest version of PhantomJS via sudo apt-get install phantomjs
  • I disabled the ufw firewall when testing
+7
python linux selenium phantomjs raspberry-pi
source share
1 answer

Ok, I'll start with the solution, for compilation there is a version of phantomjs-linux-armv6l here , on 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 way.

 pi@raspberrypi ~ $ phantomjs --version 1.9.0 pi@raspberrypi ~ $ phantomjs phantomjs> 

Now we have this, time for testing:

 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")> 

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

I tried using xvfb-run and exported the display using the shell script in init.d to run xvfb, I got a little more opportunity to run iceweasel from bash without a head without any problems, but still not cigars when it came to phantoms and selenium. I think this can lead to incompatibilities between selenium and the phantomjs version, regardless of whether it has 1.9.0, and real mute viewing is much more desirable.

I was in the middle of creating 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 easier.

I run arm6, there is also a compiled version for arm7 using 2.0.0, dependencies:

 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 

Installation procedure, I extracted the binary code to Dropbox:

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

Source link github phantomjs-2.0.0-armv7

+12
source share

All Articles