今天母亲节,写了个程序。抓取一个站点的母亲节祝福短信。实现自己主动翻页,

道友们也能够甲乙改造。比方加上节日简洁,time()模块。

一起分享吧

# -*- coding: cp936 -*-

#http://www.aizhufu.cn/duanxinku/column/89/1.html

import urllib

k=0

while k<15:             #页数

    k+=1

    url = "http://www.aizhufu.cn/duanxinku/column/89/"+str(k)+".html"

    con = urllib.urlopen(url,'r')

    content=con.read()

w2 = content.find("w2 readContent")

    nextw2 = content.find("w2 readContent",w2)

    i=0                     #每页短语条数

while w2 != -1 and nextw2 != -1 and i<11:

        w2 = content.find("w2 readContent",nextw2)

        nextw2 = content.find("w2 readContent",w2+6)

        sentence=content[w2 +31:w2+600]

        sentence = sentence[1:sentence.find("'",2)]

        i+=1

        print sentence

05-23 09:21