把微博關注的主頁網址存下來

来源:互联网 发布:数据库管理系统属于 编辑:程序博客网 时间:2024/05/16 23:50

把微博我關注了的主頁網址存下來

有其麼用呢

以後我再寫一個「和某天相比,今天我關注了的主頁有哪些增減」

#coding=utf-8import requestsimport sysimport reimport timeimport datetimedef howmanypage(cook,url):    urlre=requests.get(url,cookies=cook)    html=urlre.text    print(html.encode('utf-8'))    print('')    pagenum=re.search('" /> (\d+)/(\d+)(.*?)</div></form>',html,re.S)    return(pagenum.group(2))def findpeople(cook,url):    howmanypeople=0    f=open('people/%s.txt'%time.strftime("%Y-%m-%d"),'r')    a=f.read()    f.close()    f=open('people/%s.txt'%time.strftime("%Y-%m-%d"),'w+')    f.write(a)    urlre=requests.get(url,cookies=cook)    html=urlre.text    peoplelink=re.findall('px"><a href="(.*?)"><img src="',html,re.S)    for pl in peoplelink:        howmanypeople=howmanypeople+1        f.write(pl+'\n')    f.close()    if howmanypeople<1:        print('%s---%d'%(url,howmanypeople))    return howmanypeopleif __name__=='__main__':    cook={"Cookie":""}    i=1    url='http://weibo.cn/00000000/follow?page=%d'%i    pagenum=howmanypage(cook,url)    print(pagenum)    howmanypeople=0    f=open('people/%s.txt'%time.strftime("%Y-%m-%d"),'w+')    f.write('')    f.close()    for i in range(1,int(pagenum)+1):        print(i)        url='http://weibo.cn/00000000/follow?page=%d'%i        howmanypeople=howmanypeople+findpeople(cook,url)    f=open('people/%s.txt'%time.strftime("%Y-%m-%d"),'r')    a=f.read()    f.close()    f=open('people/%s.txt'%time.strftime("%Y-%m-%d"),'w+')    f.write('%d\n'%howmanypeople)    f.write(a)    f.close()


0 0