Python+Selenium自动化实现分页(pagination)处理,seleniumpagination
Python+Selenium自动化实现分页(pagination)处理,seleniumpagination
场景
对分页来说,我们最感兴趣的是下面几个信息
总共有多少页
当前是第几页
是否可以上一页和下一页
代码
下面代码演示如何获取分页总数及当前页数、跳转到指定页数
#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 性能优化方法小结,python性能优化
- Python中你应该知道的一些内置函数,Python内置函数
- 教大家玩转Python字符串处理的七种技巧,python七种
- 深入解答关于Python的11道基本面试题,python11道
- Python新手们容易犯的几个错误总结,python新手错误
- Python 中开发pattern的string模板(template) 实例详解,pytho
- Python中格式化format()方法详解,pythonformat
- Python 基础之字符串string详解及实例,pythonstring
- 详解Python多线程Selenium跨浏览器测试,pythonselenium
- Python中selenium实现文件上传所有方法整理总结,
评论关闭