本篇内容主要讲解“python怎么抓取B站评论数据”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“python怎么抓取B站评论数据”吧!
代码
import requests
import json
#获取oid
def get_oid(url):
ID = url.split('#')[-1]
oid_url = 'https://bangumi.bilibili.com/web_api/episode/{ID}.json'.format(ID=ID)
resp = requests.get(oid_url)
data = resp.json()
oid = data['result']['currentEpisode']['avId']
return oid
#获取评论
def get_comment(url):
oid = get_oid(url)
for page in range(1046):
url = 'https://api.bilibili.com/x/v2/reply?jsonp=jsonp&pn={page}&type=1&oid={oid}&sort=0'.format(oid=oid,page=page)
resp = requests.get(url)
data = resp.json()
comment_list = data['data']['replies']
for com in comment_list:
comment = com['content']['message']
print(comment)
start_url = 'https://bangumi.bilibili.com/anime/6301/play#113081'
get_comment(url=start_url)
到此,相信大家对“python怎么抓取B站评论数据”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
原创文章,作者:3628473679,如若转载,请注明出处:https://blog.ytso.com/tech/opensource/220034.html