Python+Selenium 자동화 페이지(pagination)처리

장면
페이지 를 나 누 는 데 있어 서 우리 가 가장 흥 미 를 느끼 는 것 은 다음 과 같은 몇 가지 정보 이다.
모두 몇 페이지 가 있 습 니까?
지금 몇 페이지 입 니까
이전 페이지 와 다음 페이지 를 사용 할 수 있 습 니까?
코드
다음 코드 는 페이지 총수 와 현재 페이지 수 를 가 져 오고 지정 한 페이지 로 이동 하 는 방법 을 보 여 줍 니 다.

#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()
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기