2、wangdailicai 2

作者在 2016-04-02 17:18:58 发布以下内容
 #-*- coding:UTF-8 -*-  # 解码方式
__author__ = 'poptest'

from selenium import  webdriver
import sys #循环退出

def findnextpage():
    drive.find_element_by_xpath(".//*[@id='pagination']/ul/li[14]/a").click()
    # 点击“下一页”的动作
    # 继续第一页的循环,只不过是起始点变了
    for i in range(1,11):
        title = drive.find_element_by_xpath("html/body/div[1]/section/div/div[2]/div/div[1]/div["+str(i)+"]/div/div[1]/h3/span").text
        if title == u"100起投,长兴8号360-5":
            sDay = drive.find_element_by_xpath("html/body/div[1]/section/div/div[2]/div/div[1]/div["+str(i)+"]/div/div[1]/div[2]/p[1]/em").text
            print sDay
            sys.exit()
        else:
            print "failed"
    findnextpage()

def findonepage():
    global drive
    global title

     #打开火狐浏览器
    drive = webdriver.Firefox()
     # 窗口最大化
    drive.maximize_window()
     #输入地址,注意下面的网址是直接打开产融贷,无需再次点击
    drive.get("http://www.firstp2p.com/deals?cate=16")
    #因为第一页有未满标的项目,所以不从第一个找。循环动作
    for i in range(5,11):
        title = drive.find_element_by_xpath("html/body/div[1]/section/div/div[2]/div/div[1]/div["+str(i)+"]/div/div[1]/h3/span").text
        if title == u"100起投,长兴8号360-5":
            sDay = drive.find_element_by_xpath("html/body/div[1]/section/div/div[2]/div/div[1]/div["+str(i)+"]/div/div[1]/div[2]/p[1]/em").text
            print sDay
            break
        else:
            print "failed"
    findnextpage()  #第一页找不见,调第二页函数,继续进行查找。


findonepage()  #调用动作
selenium | 阅读 10613 次
文章评论,共0条
游客请输入验证码