場景
對分頁來說,我們最感興趣的是下面幾個信息
總共有多少頁
當前是第幾頁
是否可以上一頁和下一頁
代碼
下面代碼演示如何獲取分頁總數及當前頁數、跳轉到指定頁數
#coding:utf-8from selenium import webdriverimport timedriver = 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"))-2print "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()
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林站長站。
新聞熱點
疑難解答