本文介紹了錯誤消息:“chromedriver"可執行文件需要是 PATH的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我剛開始使用 Selenium 并且能夠加載 google,但現在當我運行以下代碼時會產生錯誤:
I just started on Selenium and was able to load up google but now when I run the following code it produces the error:
selenium.common.exceptions.WebDriverException: Message 'chromedriver' executable needs
to be PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
為什么說C:Users/Colin/Python/chromedriver"不是路徑?
Why is it saying "C:Users/Colin/Python/chromedriver" is not a path?
from selenium import webdriver
browser = webdriver.Chrome("C:Users/Colin/Python/chromedriver")
browser.get('http://www.google.com')
browser.quit()
推薦答案
使用 Selenium v??3.x、ChromeDriver 和 Chrome 瀏覽器您可能需要通過以下任一選項將參數 executable_path
與 ChromeDriver 二進制文件的 絕對路徑 一起傳遞:
While working with Selenium v3.x, ChromeDriver and Chrome Browser you may need to pass the argument executable_path
along with the absolute path of the ChromeDriver binary through either of the following options:
- 雙反斜杠,即
(\)
- 單反斜杠,即
()
以及原始(r)
開關. - 二進制擴展名,即
(.exe)
- Double back slashes i.e.
(\)
- Single back slash i.e
()
along with the raw(r)
switch. - Binary extension i.e.
(.exe)
所以你必須換行:
browser = webdriver.Chrome("C:Users/Colin/Python/chromedriver")
與:
browser = webdriver.Chrome(executable_path=r'C:UsersColinPythonchromedriver.exe')
這篇關于錯誤消息:“chromedriver"可執行文件需要是 PATH的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!