最重要的是:webdriver及chrome-browser版本一致,否則啟動失敗
1. 安裝selenium
pip3 install selenium
2. 安裝chrome-browser
wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
yum install ./google-chrome-stable_current_x86_64.rpm
安裝完成后會顯示當前版本。
我安裝的版本是81.0.4044.138
3. 安裝chromedriver(千萬與chrome-browser版本對應)
在 http://chromedriver.storage.googleapis.com/這個頁面找對應版本的下載地址
wget http://chromedriver.storage.googleapis.com/81.0.4044.138/chromedriver_linux64.zip
解壓unzip chromedriver_linux64.zip
mv chromedriver /usr/bin即可
4. 測試
from selenium import webdriver
option = webdriver.ChromeOptions()
option.add_argument('--no-sandbox')
option.add_argument('--headless')
driver = webdriver.Chrome(chrome_options=option)
不報錯即說明安裝成功