一. 安裝Python3html
1. 進入Python官方網站:https://www.python.org/downloads/ 下載並安裝最新版本的Python(建議安裝Python3) 。python
下面是Python官網上幾個版本的區別:git
(1).web-based installer 是須要經過聯網完成安裝的github
(2) .executable installer 是可執行文件(*.exe)方式安裝web
(3) .embeddable zip file 嵌入式版本,能夠集成到其它應用中。chrome
上面3種途徑,若是有網絡,選擇web-based;api
2. 檢查是否安裝成功的方法: 在Windows命令行(cmd),輸入「python」命令來檢驗,若提示Python不是內部或者外部命令,就把Python的安裝目錄添加到系統環境變量的Path下面。瀏覽器
注意:Python3 默認已經安裝了pip, pip是一個安裝和管理Python包的工具,咱們能夠用這個工具安裝selenium,在Windows命令行(cmd)輸入pip便可看到。markdown
二. 安裝selenium網絡
1. 方法一:在聯網的狀況下,在Windows命令行(cmd)輸入pip install selenium便可自動安裝selenium,安裝完成後,輸入pip show selenium可查看當前的selenium版本,參見下圖 。
2. 方法二:直接下載selenium包:https://pypi.python.org/pypi/selenium
解壓後,在解壓目錄下執行 C:\selenium\selenium3.3.1> python3 setup.py install 便可安裝
三. 安裝三大瀏覽器驅動driver
1.chromedriver
驅動的下載地址以下:
http://chromedriver.storage.googleapis.com/index.html
2.Firefox的驅動geckodriver 下載地址:https://github.com/mozilla/geckodriver/releases/
3.IE的驅動IEdriver 下載地址:http://www.nuget.org/packages/Selenium.WebDriver.IEDriver/
注意:下載解壓後,將chromedriver.exe , geckodriver.exe , Iedriver.exe發到Python的安裝目錄,例如 D:\python 。 而後再將Python的安裝目錄添加到系統環境變量的Path下面。
而後打開Python IDLE分別輸入如下代碼來啓動不一樣的瀏覽器
啓動谷歌瀏覽器
from selenium import webdriver browser = webdriver.Chrome() browser.get('http://www.baidu.com/') 啓動火狐瀏覽器
from selenium import webdriver browser = webdriver.Firefox() browser.get('http://www.baidu.com/')
啓動IE瀏覽器
from selenium import webdriver browser = webdriver.Ie() browser.get('http://www.baidu.com/')