selenium库

一、什么是selenium库?

selenim是一个用于Web应用程序自动化测试工具,selenium测试直接运行在浏览器中

像真正的用户在操作一样,驱动浏览器执行特定的动作,如点击,下拉等操作

二、selenium在爬虫中的应用

  1. 获取动态网页中的数据,一些动态的数据我们在获取的源码中并没有显示的这一类动态加载数据
  2. 用于模拟登录

三、selenium库支持的浏览器

支持的浏览器包括phantomjs,IE(7,8,9,10,11),Mozilla Firefox,Safari,Google Chrome,Opera等

四、driver下载地址

firefox浏览器

python 复制代码
https://github.com/mozilla/geckodriver/releases/

Chrome浏览器

python 复制代码
http://chromedriver.storage.googleapis.com/index.html

113-133版本

python 复制代码
https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json

134版本及以后

https://googlechromelabs.github.io/chrome-for-testing/

链接是实时更新的

4.1 selenium调用Chrome浏览器访问动态网页数据

查看Chrome版本:

下载对应chromedriver,并配置环境变量

查看:

编写代码:

python 复制代码
import time
from selenium import webdriver

test_webdriver = webdriver.Chrome(executable_path="D:\chromedriver\chromedriver-win64\chromedriver-win64\chromedriver.exe")

test_webdriver.get("https://echarts.apache.org/examples/zh/index.html")


for item in test_webdriver.find_elements_by_xpath('//div[@class="example-title"]'):
    print(item.text)


print(test_webdriver.title)
time.sleep(10)
test_webdriver.quit()

这样就可以访问动态网页数据


相关推荐
Tinyfacture11 小时前
postman抓取登录鉴权码token及设置全局变量
测试工具·postman
川石课堂软件测试16 小时前
涨薪技术|Prometheus之HTTP API中使用PromQL
网络协议·测试工具·jmeter·http·单元测试·postman·prometheus
x10n91 天前
Postman 汉化完整指南
测试工具·lua·postman
2601_962295332 天前
如何python实现网页的自动化
python·selenium·beautifulsoup·requests·网页自动化
Luminbox紫创测控2 天前
一文读懂:准直太阳模拟器如何检测汽车AR-HUD阳光倒灌
测试工具·汽车·ar·安全性测试·太阳光模拟器·测试标准·阳光倒灌
程序员小远2 天前
自动化测试用例编写实例详解
自动化测试·软件测试·python·selenium·测试工具·职场和发展·测试用例
云雀衔光3 天前
Java Spring AI MCP:在 Spring 里把 AI 接上你的业务系统
java·开发语言·人工智能·后端·测试工具·spring
云雀衔光3 天前
MCP + 应用生成:让 AI 直接产出可交互的应用
java·人工智能·测试工具·microsoft·交互·ai编程