WebDriverException: 'chromedriver' executable needs to be in PATH

來源:互聯網
上載者:User

標籤:get   baidu   exe   配置環境變數   python   配置環境   article   網站   exception   

打算學慣用selenium + phantomJS爬取淘女郎頁面照片。

一. 先安裝lxml模組

python預設的解析器是html.parser,但lxml解析器更加強大,速度更快

1. 執行 pip install virtualenv

2. 從官方網站下載與系統,Python版本匹配的lxml檔案

http://pypi.python.org/pypi/lxml/2.3/ 

3. 執行 easy_install lxml-2.3-py2.7-win-amd64.egg

二. 安裝selenium

pip install selenium

三. 使用selenium寫個代碼,體驗一下,卻出現報錯

1 from selenium import webdriver2 3 browser = webdriver.Chrome()4 browser.get(‘http://www.baidu.com‘)

運行一下,出現報錯

原因是沒有安裝chrome瀏覽器的chromedriver(瀏覽器驅動),好了直接下載chromedriver.exe,把它放到chrome的安裝目錄下...\Google\Chrome\Application\ ,並配置環境變數,再次運行,又出現問題了:

原因:這是chrome瀏覽器版本和selenium版本不對應引起的,需要先查看chrome版本,我的版本是59:

再查看chrome瀏覽器與chromedriver的對應表,這裡這個部落格selenium之 chromedriver與chrome版本映射表(更新至v2.31),列出版本映射表:

我的版本59對應的chromedriver的版本是2.3.0或2.3.1,從http://chromedriver.storage.googleapis.com/index.html下載2.3.0,得以成功運行:

WebDriverException: 'chromedriver' executable needs to be in PATH

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.