码迷,mamicode.com
首页 > 其他好文 > 详细

获取微博用户最新发博日期

时间:2018-01-08 13:34:29      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:get   split   txt   requests   rom   mozilla   head   else   http   

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())

 

获取微博用户最新发博日期

标签:get   split   txt   requests   rom   mozilla   head   else   http   

原文地址:https://www.cnblogs.com/Erick-L/p/8241980.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!