环境:win10
1、python 3.6 anaconda3
2、安装selenium
pip install -U selenium
3、下载谷歌浏览器驱动
selenium之 chromedriver与chrome版本映射表
https://blog.csdn.net/huilan_same/article/details/51896672
驱动下载地址
http://chromedriver.storage.googleapis.com/index.html?path=2.37/
本机谷歌浏览器安装目录
C:\Program Files (x86)\Google\Chrome\Application
将chromedriver.exe放入到chrome.exe同级目录下
(如果需要安装firefox,步骤类似,但是我操作发现需要多一个添加path路径的过程
Firefox的driver下载地址:https://github.com/mozilla/geckodriver/releases
Firefox与driver对应关系: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()