arm 環境下安裝selenium+chrome


1.  升級軟件

  apt-get update

2. 安裝pip

  apt-get install python3-pip

3. 安裝selenium

  pip3 install selenium

.4.. 安裝chromedriver

  sudo apt-get install chromium-chromedriver

5. 查看安裝路徑

  dpkg -L chromium-chromedriver

 

代碼:

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')
chrome_options.add_argument("window-size=1024,768")
chrome_options.add_argument("--no-sandbox")


browser = webdriver.Chrome(chrome_options=chrome_options, executable_path="/usr/bin/chromedriver")

browser.get("http://www.baidu.com")
print(browser.page_source)
browser.close()

  

有時候會出現如下的錯誤

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/chromium-browser is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=72.0.3626.121,platform=Linux 4.14.71+ armv6l)

 

原因:

沒有添加如下代碼
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument("window-size=1024,768")
chrome_options.add_argument("--no-sandbox")

  

截圖時漢字變成方塊的問題:

安裝中文字體

apt-get -y install fontconfig xfonts-utils


免責聲明!

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



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