python 某站评论
Posted 小魏同学呀
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 某站评论相关的知识,希望对你有一定的参考价值。
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)
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])
以上是关于python 某站评论的主要内容,如果未能解决你的问题,请参考以下文章
Python爬虫以及数据可视化分析之某站热搜排行榜信息爬取分析
Python爬虫以及数据可视化分析之某站热搜排行榜信息爬取分析
python 趣味案例,通过模糊文件名,获取某站资源榜真实下载地址