把某站评论制作词云

把某站评论制作词云

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
上一篇:Oracle comment添加注释


下一篇:又拍网数据库架构案例分析