1. 程式人生 > >selenium缺少chromedriver解決方法

selenium缺少chromedriver解決方法

1.安裝好selenium,執行一段測試程式碼:

from selenium import webdriver

brower = webdriver.Chrome()
brower.get('www.baidu.com')
brower.quit()

  如果瀏覽器沒有調起來,並提示以下錯誤:selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH。

  按字面意思是chromedriver沒有設定環境變數,但其實是因為安裝chrome瀏覽器的時候通常沒有chromedriver,需要我們手動下載。

 

2.驅動版本對應chrome瀏覽器版本,下面提供兩個地址:

 

  http://chromedriver.storage.googleapis.com/index.html

  http://npm.taobao.org/mirrors/chromedriver/

 

  比如我這裡chrome版本是 70.0.3538.97,那麼我下載對應路徑下的 chromedriver_win32.zip ,64位和32位的chrome都可以使用。其他瀏覽器同理。

 

3.把剛下載的chrchromedriver放到chrome的安裝更目錄:C:\Program Files (x86)\Google\Chrome\Application ,並新增到環境變數 或者 程式碼中指定 驅動的路徑

from selenium import webdriver

brower = webdriver.Chrome('C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe')   #指定chromedriver路徑
brower.get('www.baidu.com')
brower.quit()