1.安裝瀏覽器
指定yum 源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
安裝
curl https://intoli.com/install-google-chrome.sh | bash
ldd /opt/google/chrome/chrome | grep "not found"
安裝后,執行:google-chrome-stable --no-sandbox --headless --disable-gpu --screenshot https://www.baidu.com/
報這個錯誤?我猜想是沒有UI界面的原因,到這里可以判斷安裝成功。
2. 安裝chromedriver
下載:https://npm.taobao.org/mirrors/chromedriver/
unzip 解壓
安裝完成
建立軟連接:
ln -s /opt/google/chromedriver /usr/bin/chromedriver
3.測試:
#coding=utf8 from selenium import webdriver from selenium.webdriver.chrome.options import Options chrome_options = Options() chrome_options.add_argument('--headless') chrome_options.add_argument('--disable-gpu') driver = webdriver.Chrome(chrome_options=chrome_options) #driver = webdriver.Chrome() driver.get("https://www.baidu.com") print(driver.page_source) #driver.quit()
到這里ok