查看原文
其他

【视频】抓包小练习-B站评论数据抓取

2017-09-04 大邓 大邓带你玩python

案例

https://bangumi.bilibili.com/anime/6301/play#113081

视频

https://v.qq.com/txp/iframe/player.html?vid=s05454mzeo9&width=500&height=375&auto=0

代码

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)




您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存