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()

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


相关推荐
Meta Luo10 小时前
UI 自动化测试中的等待、超时和异步加载怎么处理
功能测试·测试工具·ui·回归·自动化
Data_Journal15 小时前
如何使用 Selenium 和 Node.js 绕过 CAPTCHA
selenium
yeflx16 小时前
Ubuntu22.04下通过Wireshark抓取相机IP
tcp/ip·测试工具·wireshark
总线通信小百科18 小时前
100BASE-T1媒体转换器选型:接口、主从模式与供电怎么判断?
经验分享·测试工具
郝学胜-神的一滴19 小时前
Python浏览器自动化:Selenium与Playwright实战对比,网页爬虫&自动操作一站式指南
开发语言·爬虫·python·selenium·程序人生·自动化
测试开发技术19 小时前
AI时代我们要如何玩抓包测试:Reqable + AI Agent
软件测试·人工智能·测试工具·接口测试·agent·抓包
泽众云测试2 天前
国产化替代国外性能测试工具推荐:泽众PerformanceRunner
软件测试·测试工具·性能测试
墨云安全2 天前
自动化渗透测试工具有哪些?2026 年引擎原理、任务编排与误报抑制实践
git·测试工具·网络安全·渗透测试·自动化
芝麻馅汤圆儿2 天前
sfnt-pingpong -测试网络性能和延迟的工具
测试工具
Wokoo72 天前
Selenium 核心 API 解析(三)
python·功能测试·selenium