Skip to content

Instantly share code, notes, and snippets.

@fuzzylimes
Last active July 10, 2021 19:46
Show Gist options
  • Save fuzzylimes/5d8b1cfee24ac9e0278732ecb298b98f to your computer and use it in GitHub Desktop.
Save fuzzylimes/5d8b1cfee24ac9e0278732ecb298b98f to your computer and use it in GitHub Desktop.
Running Selenium on a Raspberry Pi 3B (Python/Firefox)

Running Selenium on a Raspberry Pi 3B

I wasted too many hours trying to get this to work. Almost every stack overflow post was useless, aside from this one. In my case, I was using Python and Firefox. The following are the steps I had to take in order to get selenium working:

1. Update packages

sudo apt-get update

2. Install firefox-esr

sudo apt-get install firefox-esr

In my case, the most recent supported version is 52.9.0. Yes this is as ancient as it looks, but it will work.

3. Obtain the correct version of geckodrvier

You MUST use a compatible geckodriver. See this page for the current support version. In my case, I needed to use 0.17.

4. Install xvfb

sudo apt-get install xvfb

This is a dependency for the next step:

5. Install the pyvirtualdisplay package, init display

This was the missing piece for me. You need to have this package and add two additional lines of code.

First add it to your project: pip install pyvirtualdisplay

Then, add the following lines to your code:

from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()

Example

from pyvirtualdisplay import Display

# Configure virtual display
display = Display(visible=0, size=(800, 600))
display.start()

# Handle scrape via selenium
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options, service_log_path=devnull)
driver.get(url)

# Do stuff here...

driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment