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

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


相关推荐
糖果店的幽灵1 小时前
AI 驱动 Selenium 测试框架最佳实践:从传统自动化到智能体测试
人工智能·selenium·自动化
cfm_29143 小时前
JVM垃圾收集算法与收集器深度解析
jvm·测试工具·算法·性能优化
Luminbox紫创测控4 小时前
金属卤素灯工作原理与汽车零部件老化测试应用
测试工具·汽车·安全性测试·测试标准
Maydaycxc6 小时前
Python 实现 RPA + AI 自动化:大模型 OCR + 网页操作完整源码实战
人工智能·python·opencv·selenium·自动化·ocr·rpa
赵大大宝6 小时前
Selenium 从入门到精通:自动化测试与爬虫实战全攻略
爬虫·selenium·测试工具
zhonghaoxincekj6 小时前
基于 168MHz MCU 的直流继电器全参数自动化测试方案解析
经验分享·功能测试·科技·学习·测试工具·创业创新·制造
带土121 小时前
5. 网络体系架构与WireShark简单使用
网络·测试工具·wireshark
kiss strong1 天前
自制请求工具request-ui
测试工具
蒲公英内测分发1 天前
在灵感与输出之间挣扎:我与 Typeoff 的交集
测试工具·产品运营·项目管理·语音输入
川石课堂软件测试1 天前
UI自动化测试|元素操作&浏览器操作实践
功能测试·测试工具·mysql·ui·docker·容器·单元测试