」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > 如何解決舊版 Google Chrome 的 Selenium Python 中的「無法找到 Chrome 二進位」錯誤?

如何解決舊版 Google Chrome 的 Selenium Python 中的「無法找到 Chrome 二進位」錯誤?

發佈於2024-11-03
瀏覽:525

How to Solve the \

在舊版Google Chrome 中無法使用Selenium Python 查找Chrome 二進位錯誤

在舊版Google Chrome 中使用Python 中的Selenium 時,您可能會遇到以下錯誤:

WebDriverException: unknown error: cannot find Chrome binary

此錯誤表示 ChromeDriver 無法在其預設位置找到 Chrome 二進位。

To要解決此問題,您可以使用 WebDriver 選項中的 binary_location 選項明確設定 Chrome 二進位位置。例如:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.binary_location = "C:\\Program Files\\Chrome\\chrome64_55.0.2883.75\\chrome.exe"
driver = webdriver.Chrome('chromedriver.exe', chrome_options=options)

確保指定的路徑指向舊 Chrome 版本的正確 Chrome 二進位位置。

或者,您可以安裝與您的 Chrome 版本相容的對應 ChromeDriver 版本。 ChromeDriver 要求文件提供了不同作業系統的預期 Chrome 二進位位置:

作業系統Chrome 的預期位置
Linux/usr/bin/google-chrome1
Mac /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
Windows XP%HOMEPATH%\Local Settings\Application Data\Google\Chrome\ Application\chrome.exe
Windows Vista及更高版本C:\Users%USERNAME%\AppData\Local\Google\Chrome\Application\chrome.exe

透過執行下列步驟,您可以防止「找不到Chrome 二進位」錯誤,並確保使用舊版Chrome 成功執行WebDriver 腳本。

最新教學 更多>

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3