selenium python (十三)對於分頁的處理


#!/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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM