1.前提
Python与Chrome路径下均安装chromedriver.exe
。
2.chromedriver.exe版本选择及下载
下载地址
为:http://npm.taobao.org/mirrors/chromedriver/
Chrome版本查看
:浏览器右上角三个点->帮助->关于Google Chrome
chromedriver.exe版本需要与浏览器版本一致
:
3.安装
下载后解压,将 chromedriver.exe复制到下面两个目录中:
Chrome目录
:比如C:\Program Files (x86)\Google\Chrome\Application
Python目录
:比如D:\Softwares\Python39
4.添加环境变量
将上述Chrome路径
添加进系统环境光变量,Python使用时应该加入环境变量了,这个就不用管了。
5.测试代码
import time
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://www.baidu.com/')
driver.find_element_by_id("kw").send_keys(u"胡皓天")
driver.find_element_by_id("su").click()