I managed to run Selenium
on CentOS
server. I have used Chromedriver
. As I found the Chromedriver
perhaps needs a browser (although the latest Chrome reportedly can run without browser...I didn't try it). But in server you don't need a GUI
to run a browser (Google-Chrome
) for this purpose.
Following are the steps I have followed:
- We need Google Chrome to be installed (IF NOT INSTALLED):
# FOR CENTOS
wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
yum localinstall google-chrome-stable_current_x86_64.rpm
# FOR UBUNTU (I didn't validate it myself, as I only worked with CentOS)
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
sudo apt-get install -f
- Now check if Google Chrome is installed by checking its version:
google-chrome --version
- If the above steps are okay, now download
Chromedriver
for your distribution and according to the Google Chrome
's version you have. To get Chromedriver
go: Chrome Driver | Downloads
- Now you have to include several options to run it. (without
--no-sandbox
the Chrome
browser won't run. Some also say to keep this option as the first option. Some other say only this option is enough....read the comments of the post mentioned in the third reference.):
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
options = Options()
options.add_argument('--no-sandbox')
options.add_argument("--headless")
options.add_argument('--disable-dev-shm-usage')
- Now show the
Chromedriver
's directory (the following shows for the current directory) and also pass these options:
driver = webdriver.Chrome('./chromedriver', options = options)
- Finally start
Selenium
's crawling:
driver.get(YOUR_DESIRED_LINK)
Reference: