Skip to content

Instantly share code, notes, and snippets.

@matthewjackowski
Created March 23, 2019 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewjackowski/4f605a64f2bb6c2db9816d43240f3826 to your computer and use it in GitHub Desktop.
Save matthewjackowski/4f605a64f2bb6c2db9816d43240f3826 to your computer and use it in GitHub Desktop.
Raspberry Pi Remote Browser
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--noerrdialogs")
chrome_options.add_argument("--disable-infobars")
chrome_options.add_argument("--kiosk")
chrome_options.add_argument("--start-maximized")
chrome_options.accept_untrusted_certs = True
chrome_options.assume_untrusted_cert_issuer = True
driver = webdriver.Chrome(executable_path='/usr/lib/chromium-browser/chromedriver',options=chrome_options)
driver.get('https://python.org')
#!/bin/bash
xset s noblank
xset s off
xset -dpms
unclutter -idle 0.5 -root &
sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' /home/pi/.config/chromium/Default/Preferences
sed -i 's/"exit_type":"Crashed"/"exit_type":"Normal"/' /home/pi/.config/chromium/Default/Preferences
while true; do
xdotool keydown ctrl+Tab; xdotool keyup ctrl+Tab;
sleep 10
done
# First remove the extra cruft from Raspian
sudo apt-get purge wolfram-engine scratch scratch2 nuscratch sonic-pi idle3 -y
sudo apt-get purge smartsim java-common minecraft-pi libreoffice* -y
sudo apt-get clean
sudo apt-get autoremove -y
# install some useful utils
sudo apt-get install xdotool unclutter sed
# this is the tricky bit, first we need to update chromium, then find a compatible chromedriver
sudo apt-get install chromium-browser
# get chromedriver from here:
# https://launchpad.net/ubuntu/trusty/+package/chromium-chromedriver
# Once you find the library you want load it via below
# curl http://launchpadlibrarian.net/361669488/chromium-chromedriver_65.0.3325.181-0ubuntu0.14.04.1_armhf.deb > chromium-chromedriver_65.0.3325.181-0ubuntu0.14.04.1_armhf.deb
# sudo dpkg -i chromium-chromedriver_65.0.3325.181-0ubuntu0.14.04.1_armhf.deb
# Next we need to setup our Python env
sudo apt-get install bzip2 libbz2-dev libreadline6 libreadline6-dev libffi-dev libssl1.0-dev sqlite3 libsqlite3-dev -y
git clone git://github.com/yyuu/pyenv.git .pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
echo 'export DISPLAY=:0' >> ~/.bashrc
. ~/.bashrc
pyenv install 3.7.2
# check that pyenv is installed ok
pyenv versions
pyenv local 3.7.2
# check that you are using the latest version
python -V
# create a virtualenv before installing libraries
python -m venv env
source env/bin/activate
pip install --upgrade pip
pip install selenium
# Be sure to allow access to your display
xhost +
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment