Python+Selenium自动化实现分页(pagination)处理
时间:2021-04-22 09:14:31|栏目:Python代码|点击: 次
场景
对分页来说,我们最感兴趣的是下面几个信息
总共有多少页
当前是第几页
是否可以上一页和下一页
代码
下面代码演示如何获取分页总数及当前页数、跳转到指定页数
#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代码
下一篇:解决Matplotlib图表不能在Pycharm中显示的问题
本文标题:Python+Selenium自动化实现分页(pagination)处理
本文地址:http://www.codeinn.net/misctech/106653.html






