把某站评论制作词云
Posted 小魏同学呀
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了把某站评论制作词云相关的知识,希望对你有一定的参考价值。
import requests
from concurrent.futures import ThreadPoolExecutor,ProcessPoolExecutor
import csv
from fake_useragent import UserAgent
ua = UserAgent()
header = {"User-Agent": ua.chrome, "Cookie": ""}
comments = []
#测试
filename=\'大笑江湖.txt\'
id=63441039
p=0
f=open(filename,mode=\'w\',encoding=\'GBK\',errors=\'ignore\')
csvwrite=csv.writer(f)
for page in range(1, 100):
url=("https://api.bilibili.com/x/v2/reply?jsonp=jsonp&type=1&oid={}&sort=2&pn=".format(id))+str(page)
html = requests.get(url, headers=header)
data = html.json()
print(url)
# print(data)
if data[\'data\'][\'replies\']!=None:
shu=len(data[\'data\'][\'replies\'])
for shus in range(0,shu):
p=p+1
print(str(p)+"------"+(data[\'data\'][\'replies\'][shus][\'member\'][\'uname\'])+"--------"+(data[\'data\'][\'replies\'][shus][\'content\'][\'message\']))
name=data[\'data\'][\'replies\'][shus][\'member\'][\'uname\']
mess=data[\'data\'][\'replies\'][shus][\'content\'][\'message\']
comments.append([name,mess])
else:
break
for k in range(0,len(comments)-1):
csvwrite.writerow(comments[k])
附件:利用某站评论的txt文件
id:F12查找oid
以上是关于把某站评论制作词云的主要内容,如果未能解决你的问题,请参考以下文章
预定热榜!!!用python分析taptap游戏评价,生成词云,源码赠送,评论送书包邮