標籤: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