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

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


相关推荐
不脱发的猴子32 分钟前
Wireshark使用教程
网络·测试工具·wireshark
waicsdn_haha5 小时前
Postman v11 安装与API测试入门教程(Windows平台)
人工智能·windows·测试工具·mysql·postman·dbeaver·rest
ITlinuxP5 小时前
2025最新Postman、Apipost和Apifox API 协议与工具选择方案解析
后端·测试工具·postman·开发工具·apipost·apifox·api协议
天才测试猿5 小时前
功能测试详解
自动化测试·软件测试·python·功能测试·测试工具·职场和发展·测试用例
海姐软件测试7 小时前
面试时,如何回答好“你是怎么测试接口的?”
测试工具·面试·职场和发展·postman
交换机路由器测试之路9 小时前
【资料分享】wireshark解析脚本omci.lua文件20250306版本发布(独家分享)
网络协议·测试工具·wireshark·lua·omci
大多_C13 小时前
selenium库工作原理
selenium·测试工具·microsoft
qq_白羊座13 小时前
selenium 组成和原理
selenium·测试工具
我是神613 小时前
Selenium库打开指定端口(9222、9333等)浏览器【已解决!!!】
selenium·谷歌浏览器·指定端口