1、下載並安裝最新的Google Chrome版本
執行如下命令:
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb sudo dpkg -i --force-depends google-chrome-stable_current_amd64.deb
2、下載並安裝最新的amd64 chromedriver版本
兩種方式(其實是兩個不同網址,但文件都一樣):
(1) 鏈接地址
https://chromedriver.storage.googleapis.com/index.html
打開以上網址,可以查看到各種對應chrome瀏覽器的chromedriver版本
手動下載需要的版本,也可以用wget下載
(2)執行如下命令(第一條用於獲取最新版本號,第二條用於下載):
LATEST=$(wget -q -O - http://chromedriver.storage.googleapis.com/LATEST_RELEASE) wget http://chromedriver.storage.googleapis.com/$LATEST/chromedriver_linux64.zip
上面兩種方式任選一個就可以了,下載后解壓得到chromedriver
解壓縮命令:unzip chromedriver_linux64.zip
然后添加執行權限:chmod +x chromedriver
把它移動到“/usr/bin”目錄下:sudo mv chromedriver /usr/bin/
3、安裝selenium
pip install selenium
4、測試
如果系統是圖形化界面,打開python,執行如下命令:
from selenium import webdriver driver = webdriver.Chrome() driver.get("https://www.baidu.com/") print(driver.title)
參考:
https://blog.csdn.net/LKLQQQQ/article/details/83316186
