4

Goal: Efficient headless browsing (with Python 3) for the Raspberry Pi

What I've Tried:

  • (using pip-3.2) Installed: selenium v2.45.0, pyvirtualdisplay v0.1.5

  • (using apt-get) Installed: xvfb (latest I think is v1.12.4?), iceweasel v31.5.3

Python 3 Code:

from selenium import webdriver
from pyvirtualdisplay import Display

display = Display(visibile=0, size=(800, 600))    # NOTE: Seems to work (non-headless)
display.start()                                   #       without these 2 lines

browser = webdriver.Firefox()
browser.get('http://www.google.com')
print(browser.page_source)
browser.quit()

Error:

Traceback (most recent call last):
  File "/home/pi/Desktop/mail-finder.py", line 18, in <module>
    browser = webdriver.Firefox()
  File "/usr/local/lib/python3.2/dist-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
self.binary, timeout),
  File "/usr/local/lib/python3.2/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
self.binary.launch_browser(self.profile)
  File "/usr/local/lib/python3.2/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 66, in launch_browser
self._wait_until_connectable()
  File "/usr/local/lib/python3.2/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 105, in _wait_until_connectable
raise WebDriverException("Can't load the profile. Profile "
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: %s If you specified a log_file in the FirefoxBinary constructor, check it for details.
Connor
  • 670
  • 3
  • 9
  • 29
  • Why don't you use PhantomJs for headless? Just curious – Saifur May 31 '15 at 18:21
  • 1
    For linux/raspberry pi, I believe you have to build PhantomJS from source. The process looked complicated and I wasn't sure how to tackle that. – Connor May 31 '15 at 18:29
  • You don't have to compile PhantomJS by yourself, there's a compiled version here: https://github.com/spfaffly/phantomjs-linux-armv6l – simeg Jun 01 '15 at 17:45

0 Answers0