在Ubuntu上安裝Chrome瀏覽器和ChromeDriver


啟動腳本后報錯 selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home

因為各種問題在ubuntu上chrome跑不起來,決定重裝,參考別人的教程

一、安裝Chrome瀏覽器

1、安裝依賴 sudo apt-get install libxss1 libappindicator1 libindicator7

2、下載Chrome安裝包 wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

3、安裝 sudo dpkg -i google-chrome*.deb sudo apt-get install -f 瀏覽器和驅動的版本一定要對應上

查看谷歌瀏覽器的版本號 google-chrome --version

國內可以訪問下面的地址下載chrome http://npm.taobao.org/mirrors/chromedriver/ 點開一個驅動版本有個notes.txt文件 里面有瀏覽器和驅動的版本對應

二、安裝ChromeDriver

1、安裝xvfb以便我們可以無頭奔跑地運行Chrome sudo apt-get install xvfb

2、安裝依賴 sudo apt-get install unzip

3、下載安裝包 wget -N http://chromedriver.storage.googleapis.com/2.38/chromedriver_linux64.zip

4、解壓縮+添加執行權限 unzip chromedriver_linux64.zip

5、移動 sudo mv -f chromedriver /usr/local/share/chromedriver

6、建立軟連接

sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver

sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver

三、無頭運行Chrome

1、安裝Python依賴

pip3 install selenium

pip3 install pyvirtualdisplay

2、開干

from pyvirtualdisplay import Display

from selenium import webdriver

display = Display(visible=0, size=(800, 600))  # 初始化屏幕 display.start()  

driver = webdriver.Chrome()  # 初始化Chrome

driver.get('http://www.cnblogs.com/x54256/')

print(driver.title)


免責聲明!

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



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