1、安新selenium
? ?cmd命令行安裝。使用以下命令安裝selenium:? ?pip install -U selenium
2、下載chromedriver,并放在python的安裝根目錄下。
??注意:chromedriver要與chrome版本匹配才可以。
? ? ?chromedriver下載地址: http://npm.taobao.org/mirrors/chromedriver/
? ? ?在此地址中,有非常多的chromedriver版本。需要找到能夠支持你當前安裝的chrome版本的驅動。
有windows、linux、mac三個平臺的驅動。除此之外,有notes.txt文件。打開這個文件,可以看到當前版本的chromedriver支持哪些版本的chrome.
若是windows平臺,無論是32位還是64位,都下載?chromedriver_win32.zip.
? 將其解壓到?python?安裝目錄下面即可。
?至此環境安裝完成。
? ? 如果是ie,firefox,只需要將驅動程序換成ieserverdriver,或者?geckodriver即可。其它的步驟都完全?一樣。
檢測環境是否成功
? ?打開pycharm,新建一個python文件,在其中輸入以下代碼并運行:
from seleniumimport webdriver
driver=webdriver.Chrome()
driver.get("http://www.baidu.com")
如果能運行打開谷歌瀏覽器的百度頁面,那么就是安裝成功了
瀏覽器驅動下載地址匯總:
Chrome:?https://sites.google.com/a/chromium.org/chromedriver/downloads? .? ? ? ?國內鏡像地址:http://npm.taobao.org/mirrors/chromedriver/
Edge:https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
Firefox:https://github.com/mozilla/geckodriver/releases
Safari:https://webkit.org/blog/6900/webdriver-support-in-safari-10/