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

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


相关推荐
xiecoding.cn1 小时前
Selenium IDE下载和安装教程(附安装包)
selenium·测试工具·selenium安装·selenium ide·selenium ide下载·selenium下载
.又是新的一天.3 小时前
04-Fiddler详解+抓包定位问题
前端·测试工具·fiddler
有谁看见我的剑了?3 小时前
web站点基准测试工具ab命令学习
测试工具·ab测试
金玉满堂@bj4 小时前
我是程序员吗?
测试工具·可用性测试
安冬的码畜日常20 小时前
【JUnit实战3_20】第十一章:用 Gradle 运行 JUnit 测试实战
测试工具·junit·单元测试·gradle·软件构建·groovy·junit5
张永清-老清21 小时前
每周读书与学习->JMeter主要元件详细介绍(三)逻辑控制器
测试工具·jmeter·压力测试·性能调优·jmeter性能测试·性能分析·每周读书与学习
程序员三藏1 天前
如何使用Selenium做自动化测试?
自动化测试·软件测试·python·selenium·测试工具·职场和发展·测试用例
安冬的码畜日常1 天前
【JUnit实战3_19】第十章:用 Maven 3 运行 JUnit 测试(下)
java·测试工具·junit·单元测试·maven·junit5
安冬的码畜日常1 天前
【JUnit实战3_18】第十章:用 Maven 3 运行 JUnit 测试(上)
测试工具·junit·maven·artifact·junit5
交换机路由器测试之路1 天前
发包工具anysend使用手册
网络·测试工具·ipv6·发包工具