Created
January 18, 2020 02:52
-
-
Save tovask/8981abf02612ac28c710db78ad82a3a8 to your computer and use it in GitHub Desktop.
Selenium (with Firefox) setup on headless linux (debian)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# https://seleniumhq.github.io/selenium/docs/api/py/ | |
# https://www.seleniumhq.org/docs/04_webdriver_advanced.jsp | |
# https://intoli.com/tags/selenium/ | |
set -e -x | |
su -c 'apt-get install xvfb firefox-esr' | |
wget https://bootstrap.pypa.io/get-pip.py -O get-pip.py | |
su -c 'python get-pip.py' | |
su -c 'pip install selenium' | |
su -c 'pip install PyVirtualDisplay' | |
wget https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-linux64.tar.gz | |
tar -x geckodriver -zf geckodriver-v0.24.0-linux64.tar.gz | |
su -c 'mv geckodriver /usr/bin/geckodriver' | |
# let's try it | |
cat <<-EOF | python | |
from pyvirtualdisplay import Display | |
from selenium import webdriver | |
display = Display(visible=0, size=(800, 600)) | |
display.start() | |
browser = webdriver.Firefox() | |
browser.get('https://seleniumhq.github.io/selenium/docs/api/py/') | |
print browser.title | |
browser.quit() | |
display.stop() | |
EOF | |
# or | |
export DISPLAY=:1 | |
Xvfb $DISPLAY -screen 0 1920x1080x16 & | |
# disown | |
cat <<-EOF | python | |
from selenium import webdriver | |
browser = webdriver.Firefox() | |
browser.get('https://www.seleniumhq.org/docs/04_webdriver_advanced.jsp') | |
print browser.title | |
browser.quit() | |
EOF | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment