【爬虫+数据清洗+可视化分析】Python文本分析《狂飙》电视剧的哔哩哔哩评论
import requests
import json
import pandas as pd
from wordcloud import WordCloud
import matplotlib.pyplot as plt
# 请求API获取评论数据
def get_comments(video_id, offset=0, limit=20):
url = f'https://api.bilibili.com/x/v2/reply/main?oid={video_id}&type=1&pn={offset//20+1}&ps={limit}'
headers = {
'User-Agent': 'Mozilla/5.0',
'Cookie': 'LIVE_BUVID=AUTO52929463712191798; CURRENT_FNVAL=16; buvid3=AE85047F-08D8-4ECA-8E2D-67294E8673A018041infoc; rpdid=|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J|(J|)J|J
评论已关闭