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

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


相关推荐
啊阿狸不会拉杆2 小时前
《计算机网络-自顶向下方法》2.8 小结、课后习题和 Wireshark 实验 读书笔记
计算机网络·测试工具·wireshark·因特网
PS测5 小时前
Linux压力测试工具stress,能精确控制 CPU、内存、IO 负载类型和持续时间
测试工具
2601_9623878210 小时前
web自动化测试实战教程【selenium/unittest/pytest】【共193课
selenium·pytest·devops·web自动化测试·unittest
qianshi121312 小时前
涂层划痕测试仪-精准评估涂层附着力,兼顾科研与工业质量检测
经验分享·测试工具·百度
PhotonixBay12 小时前
3D共聚焦显微镜与探针式粗糙度仪:谁更适合亚表面损伤检测?
图像处理·人工智能·测试工具·3d
2601_9622972512 小时前
Python、Pytest、Allure、Selenium和Jenkins实现自动化测试集成实例
python·selenium·jenkins·pytest·allure
qianshi121313 小时前
电化学腐蚀摩擦磨损试验机的工作原理、操作流程、适用范围行业和产品特点
测试工具·百度
是吕先森14 小时前
【python】selenium实现web自动化测试
前端·python·selenium
Luminbox紫创测控14 小时前
车载AR-HUD阳光倒灌与热效应:太阳光模拟器如何复现太阳辐射?
测试工具·汽车·ar·安全性测试·测试标准