Python+Selenium自动化实现分页(pagination)处理
作者:ForcePush 时间:2022-02-23 20:09:52
场景
对分页来说,我们最感兴趣的是下面几个信息
总共有多少页
当前是第几页
是否可以上一页和下一页
代码
下面代码演示如何获取分页总数及当前页数、跳转到指定页数
#coding:utf-8
from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.get("https://segmentfault.com/news")
# 获得所有分页的数量
# -2是因为要去掉上一个和下一个
total_pages = len(driver.find_element_by_class_name("pagination").find_elements_by_tag_name("li"))-2
print "total_pages is %s" %(total_pages)
# 获取当前页面是第几页
current_page = driver.find_element_by_class_name('pagination').find_element_by_class_name('active')
print "current page is %s" %(current_page.text)
#跳转到第二页
next_page = driver.find_element_by_class_name("pagination").find_element_by_link_text("2")
next_page.click()
标签:Python,Selenium,分页
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
使用python+poco+夜神模拟器进行自动化测试实例
2022-12-19 09:09:29
![](https://img.aspxhome.com/file/2023/8/92178_0s.jpg)
利用Python如何实现一个小说网站雏形
2023-09-22 05:52:07
Symfony控制层深入详解
2023-11-14 20:43:33
![](https://img.aspxhome.com/file/2023/6/92806_0s.png)
Python自动化之批量处理工作簿和工作表
2023-02-16 08:07:30
python中openpyxl库用法详解
2023-07-15 09:53:45
![](https://img.aspxhome.com/file/2023/2/60722_0s.png)
在Python开发环境中调用ChatGPT模型详细过程
2022-03-25 21:59:29
![](https://img.aspxhome.com/file/2023/3/97603_0s.jpg)
asp如何调用DLL来加快服务器的执行速度?
2009-11-15 20:07:00
PyCharm代码格式调整方法
2021-05-21 14:59:32
Opera浏览器简介
2009-02-05 20:56:00
Python webargs 模块的简单使用
2021-02-27 11:56:04
asp Access数据备份,还原,压缩类代码
2011-03-07 11:16:00
Ranorex通过Python将报告发送到邮箱的方法
2021-08-17 03:57:43
![](https://img.aspxhome.com/file/2023/4/97654_0s.png)
Pandas实现自定义Excel格式并导出多个sheet表
2022-10-04 18:46:34
![](https://img.aspxhome.com/file/2023/4/76114_0s.png)
python矩阵转换为一维数组的实例
2023-09-13 18:34:10
Dreamweaver使用快技法十三则
2009-07-21 12:45:00
Python实现用手机监控远程控制电脑的方法
2021-06-22 07:57:49
Python标准库之随机数 (math包、random包)介绍
2021-09-26 11:57:08
web开发以HTML为中心
2008-02-13 08:14:00
![](https://img.aspxhome.com/file/UploadPic/20082/13/200821382345331s.png)
python多进程程序打包成exe的问题
2023-08-07 13:39:03
Django nginx配置实现过程详解
2022-11-09 11:42:58