1. download and download chrome
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt install ./google-chrome-stable_current_amd64.deb
2. check chrome version and install corresponding chromedriver
chromedriver:
wget https://sites.google.com/a/chromium.org/chromedriver/downloads
sudo unzip chromedriver_linux64.zip
sudo cp chromedriver /usr/bin -v
3. install splinter in python
pip3 install splinter
4. source code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-
import requests
from splinter import Browser
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-dev-shm-usage')
br = Browser('chrome',options=chrome_options)
print(br.evaluate_script("4+4") == 8)
issue 1:
chrome cannot be started by click chrome app:
solution:
rm ~/.config/google-chrome/*
issue 2:
chrome is no longer running so ChromeDriver is assuming that Chrome has crashed
solution:
1.install corresponding chrome driver to chrome webserver
https://sites.google.com/a/chromium.org/chromedriver/downloads
2. Make sure that --no-sandbox option is the first option in chromeoption
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')