1.selenium用pip安裝:
pip install selenium
2.chromedriver的安裝
【安裝須知】chromedriver 必須與 Chrome 版本一致,不然就不起作用。可在谷歌瀏覽器地址欄中輸入以下代碼查看:chrome://version/
chromedriver普通全版有兩個下載地址:
a、http://chromedriver.storage.googleapis.com/index.html
b、https://npm.taobao.org/mirrors/chromedriver/
=========♥反爬厲害網站專用 ♥=========================================
1.chromedriver修改版,淘寶專用:微雲上(版本:76.0.3809.100(正式版本) (64 位)):
鏈接:https://share.weiyun.com/5y1fKnq 密碼:uefgq3
2.chrome下載(版本:76.0.3809.100(正式版本) (64 位)):
https://www.newasp.net/soft/78040.html
==================================================================
3.配置chromedriver
1.解壓壓縮包,找到chromedriver.exe復制到chrome的安裝目錄(其實也可以隨便放一個文件夾,只要有環境變量配置過的即可)
2.復制chromedriver.exe文件的路徑並加入到電腦的環境變量中去。【環境變量:計算機——屬性——高級系統設置——環境變量】
進入環境變量編輯界面,添加到用戶變量即可,雙擊PATH,將你的文件位置(C:\Program Files (x86)\Google\Chrome\Application\)添加到后面,注意各路徑間加分號。
3.完成后在cmd下輸入: chromedriver 驗證是否安裝成功:
.測試
a.未配置環境也可以測試,輸入如下代碼:
from selenium import webdriver import time def main(): chrome_driver = 'C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe' #chromedriver的文件位置 b = webdriver.Chrome(executable_path = chrome_driver) b.get('https://www.google.com') time.sleep(5) b.quit() if __name__ == '__main__': main()
b.已配置環境變量時,就用下面這個測試:
from selenium import webdriver import time def main(): b = webdriver.Chrome() b.get('https://www.baidu.com') time.sleep(5) b.quit() if __name__ == '__main__': main()
錯誤:運行如提示以下信息,就可能是版本不對: