第四次作业

# 获取微博中我关注的信息

import requests

import json

import re

headers = {

    'User-Agent':'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Mobile Safari/537.36',

    'cookie':'ALF=1562986173; SCF=AguB0OuWjlUZniH81MFjp1v_dN9jYfcb5EhoB7pG4LSeP4LUcDelJIl2cHVvlh7JR4rznDtY-KPUB0ngTEOI3q4.; SUB=_2A25wBcmMDeRhGeRJ61oQ9SrFzDyIHXVTCdfErDV6PUJbktANLWvdkW1NUsQPeHgxMgBXoB6qMGst5p6FlwTtWZmR; SUBP=0033WrSXqPxfM725Ws9jqgMF55529P9D9W5md0Co0PbSEWirTAxEHqZA5JpX5K-hUgL.FozNehnpSKB4S052dJLoIEHbdsLV9cijIg4ri--fiKyhiKnfi--fi-82iK.7i--4iK.0i-iW; SUHB=0HTQlPahfD1jBB; SSOLoginState=1560394205; _T_WM=74406650744; WEIBOCN_FROM=1110105030; MLOGIN=1; M_WEIBOCN_PARAMS=lfid%3D1076032708154970%26luicode%3D20000174%26uicode%3D20000174; XSRF-TOKEN=1e350f'

}

url = 'https://m.weibo.cn/feed/friends?'

def get_info (url,page):

    res = requests.get(url,headers=headers)

    json_data = json.loads(res.text)

    # print(json_data)

    statuses = json_data['data']['statuses']

    for statuse in statuses :

        text = statuse['text']

        new_text = re.sub('[a-zA-Z0-9\s<="_>:/.?%]+','',text,re.S)

        print(new_text)

    next_cursor = json_data['data']['next_cursor']

    # print(next_cursor)

    page = page + 1

    if page <= 20:

        next_url = 'https://m.weibo.cn/feed/friends?max_id={}'.format(next_cursor)

        get_info(next_url, page)

    else:

        pass

get_info(url,1)

你可能感兴趣的:(第四次作业)