Skip to content

Instantly share code, notes, and snippets.

@lohjine
Created August 28, 2020 10:56
Show Gist options
  • Save lohjine/4515fc32fcaf6c9d0ba33311111565c9 to your computer and use it in GitHub Desktop.
Save lohjine/4515fc32fcaf6c9d0ba33311111565c9 to your computer and use it in GitHub Desktop.
Set up headless selenium with chromedriver
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--window-size=1920x1080")
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_driver = r"chromedriver"
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=chrome_driver)
pip3 install selenium
## ONLY CAN BE DONE AS ROOT
sudo su root
sudo curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add
sudo echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list
sudo apt-get -y update
sudo apt-get -y install google-chrome-stable
## back to normal user
exit
wget https://chromedriver.storage.googleapis.com/79.0.3945.36/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
chmod +x chromedriver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment