環(huán)境:win10
1管钳、python 3.6 anaconda3
2、安裝selenium
pip install -U selenium
3玲献、下載谷歌瀏覽器驅(qū)動(dòng)
selenium之 chromedriver與chrome版本映射表
https://blog.csdn.net/huilan_same/article/details/51896672
驅(qū)動(dòng)下載地址
http://chromedriver.storage.googleapis.com/index.html?path=2.37/
本機(jī)谷歌瀏覽器安裝目錄
C:\Program Files (x86)\Google\Chrome\Application
將chromedriver.exe放入到chrome.exe同級目錄下
(如果需要安裝firefox殉疼,步驟類似,但是我操作發(fā)現(xiàn)需要多一個(gè)添加path路徑的過程
Firefox的driver下載地址:https://github.com/mozilla/geckodriver/releases
Firefox與driver對應(yīng)關(guān)系:https://blog.csdn.net/u013250071/article/details/78803230 )
4捌年、編寫代碼:
#!coding=utf-8
from selenium import webdriver
chromedriver = "C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe"
driver = webdriver.Chrome(chromedriver)
driver.get("http://www.baidu.com")
driver.find_element_by_id("kw").send_keys("selenium")
driver.find_element_by_id("su").click()