debian/ubuntu install chrome by command line and chromeheadless parameter description
目录
chrome install:
1 2 |
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb dpkg -i google-chrome-stable_current_amd64.deb |
if you get some error:
1 2 |
apt -f install dpkg -i google-chrome-stable_current_amd64.deb |
installed successfully:
1 2 3 |
root@nodekr:~# google-chrome [10305:10305:0629/152221.083012:ERROR:zygote_host_impl_linux.cc(88)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180. root@nodekr:~# |
selenium install:
1 |
pip install selenium |
webdriver for chrome install:
1 2 3 4 5 |
wget https://chromedriver.storage.googleapis.com/2.40/chromedriver_linux64.zip unzip chromedriver_linux64.zip mv chromedriver /usr/bin/ cd /usr/bin/ chmod 777 chromedriver |
test in python:
1 2 3 4 5 6 7 8 9 |
from selenium import webdriver from selenium.webdriver.chrome.options import Options chrome_options = Options() chrome_options.add_argument("--no-sandbox") chrome_options.add_argument('--headless') d = webdriver.Chrome(chrome_options=chrome_options) d.get("https://cpp.la") d.current_url d.quit() |
chromeheadless parameter description:
1 2 3 4 5 6 7 8 9 10 |
chrome_options.add_argument("--headless") chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--disable-extensions") chrome_options.add_argument("--disable-gpu") chrome_options.add_argument("--disable-logging") chrome_options.add_argument("--log-level=3") chrome_options.add_argument("--single-process") chrome_options.add_argument("--incognito") chrome_options.add_argument("--disable-application-cache") chrome_options.add_argument('--user-agent="Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1"') |
by cpp.la 20180629