linux 無界面環境安裝chrome,chromedriver,selenium


注意 chrome和chromedriver 大版本號要一致

一、安裝chrome

1. 下載安裝腳本,

在下載目錄中,執行以下命令,將安裝腳本下載到本地

wget https://intoli.com/install-google-chrome.sh

  

2.然后授予可執行權限

chmod 755 ./install-google-chrome.sh

  

3.執行腳本

./install-google-chrome.sh

 

安裝腳本會自動下載、安裝chrome(合適的版本),並且目前兩個系統中,所缺少的依賴,都會被安裝。

4.測試安裝結果

執行命令, 

google-chrome-stable --no-sandbox --headless --disable-gpu --screenshot https://www.baidu.com/

  

如果在當前文件夾中出現screenshot.png  則安裝成功

5.查看linux 安裝的谷歌瀏覽器版本

# google-chrome --version
Google Chrome 83.0.4103.106

  

二、安裝chromedriver

1. 在  https://npm.taobao.org/mirrors/chromedriver中找到對應版本的chromedriver

 

2.下載文件包

wget https://npm.taobao.org/mirrors/chromedriver/75.0.3770.90/chromedriver_linux64.zip

  

3.解壓文件包

unzip chromedriver_linux64.zip

  

解壓后,在/opt/google/ 會多出一個文件chromedriver

4.修改chromedriver 執行權限

chmod +x chromedriver

  

5.連接文件

ln -s /opt/google/chromedriver /usr/bin/chromedriver 

三.安裝selenium

yum install Xvfb

pip install pyvirtualdisplay

pip install selenium

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM