selenium是什么?

直白来讲,他就是一个‘模拟用户点击页面的操作’的编程工具

安装selenium

下载python和pychram并安装(附下载链接)
python官网:https://www.python.org/
pychram官网:https://www.jetbrains.com/pycharm/

安装浏览器Webdriver驱动(用于程序启动浏览器)
Chrome浏览器驱动下载地址:http://chromedriver.storage.googleapis.com/index.html
Firfox浏览器驱动下载地址:https://github.com/mozilla/geckodriver/releases
IE浏览器驱动下载地址:http://docs.seleniumhq.org/download/
Edge浏览器驱动下载地址:https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/

找到对应浏览器的版本,点击下载,里面文件放进python根目录,点击返回成功即可。

以Chrome为例,参考教程如下:

1、找到浏览器对应的版本

初使selenium_下载地址


2、寻找对应版本的驱动包

初使selenium_python_02


3、解压并放置python根目录,点击安装,返回successfully代表安装成功

初使selenium_selenium_03

win+R输入cmd进入窗口命令输入

pip install selenium

打开pychram,创建一个python file

from selenium import webdriver
from time import sleep

driver = webdriver.Chrome()#打开浏览器
driver.get('https://www.baidu.com/')#打开网址
driver.find_element('id','kw').send_keys('KrityCat')#输入框输入KriyCat
driver.find_element('id','su').click()#点击查询按钮
driver.time = sleep(3)#睡眠3秒
driver.quit()#关闭浏览器

Ctrl+Shift+F10运行该程序,就能看到selenium运行过程。

该文章用于个人记录,如有疑问请留意。