Created
January 18, 2020 06:21
-
-
Save e96031413/568ad2773acd646652201c749d10fc94 to your computer and use it in GitHub Desktop.
How to install selenium and chromedriver on Linux OS
This file contains 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
sudo apt-get update | |
sudo apt-get install -y unzip openjdk-8-jre-headless xvfb libxi6 libgconf-2-4 | |
# Install Chrome. | |
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 | |
# Install ChromeDriver. | |
wget -N https://chromedriver.storage.googleapis.com/79.0.3945.36/chromedriver_linux64.zip -P ~/ | |
unzip ~/chromedriver_linux64.zip -d ~/ | |
rm ~/chromedriver_linux64.zip | |
sudo mv -f ~/chromedriver /usr/local/bin/chromedriver | |
sudo chown root:root /usr/local/bin/chromedriver | |
sudo chmod 0755 /usr/local/bin/chromedriver | |
# Install Selenium | |
pip install selenium | |
# Test it.(save the code below as .py file) | |
from selenium import webdriver | |
from selenium.webdriver.chrome.options import Options | |
CHROMEDRIVER_PATH = '/usr/local/bin/chromedriver' | |
WINDOW_SIZE = "1920,1080" | |
chrome_options = Options() | |
chrome_options.add_argument("--headless") | |
chrome_options.add_argument("--window-size=%s" % WINDOW_SIZE) | |
chrome_options.add_argument('--no-sandbox') | |
driver = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH,chrome_options=chrome_options) | |
driver.get("https://www.google.com") | |
print(driver.title) | |
driver.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment