新浪微博爬虫便携版

需要调整的参数是新冠肺炎和page,返回一页的数据

import requests
import pandas as pd
import json
import re


def get_one_page():
    one_page_data = []
    params = {
        'containerid': '100103type=60&q=新冠肺炎&t=0',
        'page_type': 'searchall',
        'page': 1
    }
    url = 'https://m.weibo.cn/api/container/getIndex'# 请求api
    response = requests.get(url,params=params).text
    cards = json.loads(response)['data']['cards']
    for card in cards:
        blog_data = card['mblog']
        text = re.sub('<.*?>','',blog_data['text'])  # 文章内容
        mid = blog_data['mid']  # 文章id
        reposts_count = blog_data['reposts_count']  # 转发数
        comments_count = blog_data['comments_count']  # 评论数
        attitudes_count = blog_data['attitudes_count']  # 点赞数
        data = [text,mid,reposts_count,comments_count,attitudes_count]
        column = ['text','mid','reposts_count','comments_count','attitudes_count']
        one_page_data.append(dict(zip(column,data)))
    return one_page_data


if __name__ == '__main__':
    data = get_one_page()
    print(data)
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 1024 设计师:白松林 返回首页