問(wèn)題描述
我剛開(kāi)始使用 Selenium 并且能夠加載 google,但現(xiàn)在當(dāng)我運(yùn)行以下代碼時(shí)會(huì)產(chǎn)生錯(cuò)誤:
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
為什么說(shuō)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 瀏覽器您可能需要通過(guò)以下任一選項(xiàng)將參數(shù) executable_path
與 ChromeDriver 二進(jìn)制文件的 絕對(duì)路徑 一起傳遞:
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)
開(kāi)關(guān). - 二進(jìn)制擴(kuò)展名,即
(.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')
這篇關(guān)于錯(cuò)誤消息:“chromedriver"可執(zhí)行文件需要是 PATH的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!