#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'zuoanvip'
#对于web上分页的功能,一般做如下操作:
#获取总页数
#翻页操作(上一页、下一页)
from selenium import webdriver
from time import sleep
driver = webdriver.Firefox()
driver.get('http://www.xx.com')
#获取总页数(通过二次定位方法进行定位)
total_pages = len(driver.find_element_by_tag_name('select').find_element_by_tag_name('option'))
print 'The total page is %s'%(total_pages)
#再次获取所分页,并执行翻页操作
total_page = driver.find_element_by_tag_name('select').find_element_by_tag_name('option')
for page in total_page:
page.click()
============================================================
代码片段:
<select id="pageE1m_a74e_ce2c" class="yem" action="page" data_page="5">
<option value="1">1/5</option>
<option value="1">2/5</option>
<option value="1">3/5</option>
<option value="1">4/5</option>
<option value="1">5/5</option>
</select>