获取微博用户最新发博日期
import requests import json from dateutil.parser import parse import time headers = { 'User-Agent':'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1', 'Cookie':'_T_WM=83d7b2f90b590cf94ca2e80e205a996b; ALF=1517968547; SCF=As_oBCk6ZiltkfcLF4iuu96t5FXlmkbfmnbphtwClOcqgGdrILfH9L3K2IHD9wOyU4jpqmsICpm0wpR-GIwocw0.; SUB=_2A253VpEoDeRhGeVM6lIU8izEwjyIHXVUuD9grDV6PUJbktAKLWzHkW1NTL07qykVZZ0QE_0mgszu06yO5a_vqR6P; SUBP=0033WrSXqPxfM725Ws9jqgMF55529P9D9WhQMFyM94ynlSl9JBZenkS15JpX5K-hUgL.FoeEeK5feozR1K52dJLoI7D8MJLoIEfeKX4G; SUHB=0u5RezFXbe-d5U; SSOLoginState=1515381111; WEIBOCN_FROM=1110006030; M_WEIBOCN_PARAMS=fid%3D1005053210522890%26uicode%3D10000011', 'Referer':'https://m.weibo.cn/profile/6022546458', } def newst_post(uid): url = 'https://m.weibo.cn/profile/info?uid=%s'%(uid) res = requests.get(url,headers = headers) fise_data = json.loads(res.text)['data']['statuses'][:2] if len(fise_data) >=2: try: a = str(parse(fise_data[0]['created_at'][4:])).split(' ')[0] b = str(parse(fise_data[1]['created_at'][4:])).split(' ')[0] print(str(uid)+" "+ a) if a > b else print(str(uid)+" "+ b) except Exception as e: print(str(uid)+" "+e) elif 0 < len(fise_data)<=1: c = str(parse(fise_data[0]['created_at'][4:])).split(' ')[0] print(str(uid)+" "+ c) else: print(str(uid)+" "+ "无微博") with open('all_uid.txt','r') as f: for i in f: newst_post(i.strip())