今天用到selenimu中的webdriver,在安裝外selenium後,輸入以下程式出現錯誤:"' chromedriver' executable needs to be in PATH":
from selenium import webdriver
chromedriver = "C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe" #配置一下環境變量也可
driver= webdriver.Chrome(chromedriver)
driver.get('http://www.baidu.com')
查資料後是因為:
1.沒有下載下傳對應的chromedriver程式,下載下傳浏覽器對應版本的chromedriver版本
附錄:連結chromedriver和浏覽器對應版本: https://sites.google.com/a/chromium.org/chromedriver/home
2.将chromedriver程式加在項目目錄下或者配置相關的環境變量也可
同樣對應pahntomjs子產品也是這樣,報錯資訊‘WebDriverException: Message: 'phantomjs' executable needs to be in PATH. ’
對應下載下傳phantomjs連結:http://phantomjs.org/download.html
也可以采用上述兩種方法解決錯誤
browser=webdriver.PhantomJS(executable_path=r'C:\Users\lyh\Anaconda2\phantomjs-2.1.1-windows\bin\phantomjs.exe')