- 我的電腦已安裝python3.5並配置號環境變量
- 驗證python安裝無異常:在cmd中輸入python,顯示安裝的python版本號
- 在官網下載Firefox:https://www.firefox.com.cn
- 下載對應版本的geckodriver:https://github.com/mozilla/geckodriver/releases,並將geckodriver.exe放置python安裝根目錄下,與python.exe同級
- 打開cmd,准備安裝selenium
- 輸入pip
- cmd輸入指令安裝在線安裝selenium
- >pip install selenium==2.53.6
- 等到進度顯示100%,安裝完成
- 提示有可用的新版本安裝: python -m pip install --upgrade pip
- 檢查selenium環境
- 輸入以下語句,查看firefox是否打開
-
python >>> from selenium import webdriver >>> webdriver.Firefox()
-
如果誤輸入為firefox,會報error
- 提示error sessionid,更新selenium版本:
pip install
-
U selenium
-
- 至此環境搭建完成,打開百度首頁
-
python >>> from selenium import webdriver >>>driver=webdriver.Firefox() >>>driver.get("https://www.baidu.com")