把微博我關注了的主頁網址存下來
有其麼用呢
以後我再寫一個「和某天相比,今天我關注了的主頁有哪些增減」
#coding=utf-8
import requests
import sys
import re
import time
import datetime
def 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 howmanypeople
if __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()