Created
August 28, 2020 10:56
-
-
Save lohjine/4515fc32fcaf6c9d0ba33311111565c9 to your computer and use it in GitHub Desktop.
Set up headless selenium with chromedriver
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
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) |
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
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