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

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


相关推荐
光影62720 小时前
Selenium自动化测试---实战踩坑实录
python·selenium·测试工具·百度
掌动智能1 天前
传统数据工厂之死:RunnerAgent如何开启AI驱动的“数据生产”新纪元
人工智能·测试工具·自动化
wuchen10042 天前
使用Postman测试grpc接口-传参错误的反例
测试工具·postman
蒲公英内测分发2 天前
Typeoff 实时润色体验:语音转文字让写作效率提升 3 倍
测试工具·产品运营·项目管理
Luminbox紫创测控2 天前
氙灯太阳光模拟器加速老化测试
人工智能·测试工具·测试标准
wangl_922 天前
Wireshark 使用指南:从入门到高级分析
网络·网络协议·tcp/ip·测试工具·wireshark·modbus
Byron Loong2 天前
【网络】Wireshark过滤器表达式的规则
网络·测试工具·wireshark
MESMarketing2 天前
互动分享 | Shift-Left实践落地
功能测试·测试工具·自动化·自动驾驶·敏捷开发
lifewange3 天前
主流性能诊断工具
测试工具
程序员杰哥3 天前
独立搭建UI自动化测试框架
自动化测试·软件测试·python·selenium·测试工具·ui·测试用例