弹幕全是“二刷”,这部剧有多好看?Python爬取腾讯视频1.1W弹幕,做词云分析
《猎罪图鉴》可以说是国产悬疑剧之光了,上线首周热度不断飙升。
该剧讲述了因一起尘封旧案而结怨的模拟画像师沈翊和刑警队长杜城,在机缘巧合下被迫搭档,两人联手侦破多起离奇疑案,共同追踪谜底真相的故事。
今天就用Python爬取该剧弹幕,做词云图
环境介绍
python 3.8
pycharm
requests >>> pip install requests
pyecharts >>> pip install pyecharts
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36'
}
for page in range(15, 1500, 30):
url = f'https://mfm.XXXX.com/danmu?otype=json&target_id=7712618480%26vid%3Dg00423lkmas&session_key=0%2C0%2C0×tamp={page}&_=1647931110703'
response = requests.get(url=url, headers=headers)
json_data = response.json()
for comment in json_data['comments']:
commentid = comment['commentid']
opername = comment['opername']
content = comment['content']
with open('弹幕.csv', encoding='utf-8-sig', mode='a', newline='') as f:
csv_writer = csv.writer(f)
csv_writer.writerow([commentid, opername, content])
wordlist = []
data = pd.read_csv('弹幕.csv')['content']
data
a = [list(z) for z in zip(word, count)]
c = (
WordCloud()
.add('', a, word_size_range=[10, 50], shape='circle')
.set_global_opts(title_opts=opts.TitleOpts(title="词云图"))
)
c.render_notebook()