import requests import json import re def get_cid(bv): url = 'https://api.bilibili.com/x/player/pagelist?bvid=%s' % bv res = requests.get(url) res_text = res.text res_dict = json.loads(res_text) cid = res_dict['data'][0]['cid'] return cid def get_bullet_chat(cid): url = 'https://api.bilibili.com/x/v1/dm/list.so?oid=%s' % cid res = requests.get(url) res.xml = res.content.decode('utf-8') patt = re.compile('<d.*?>(.*?)</d>') bullet_list = patt.findall(res.xml) return bullet_list def wold_count(bullent): bullent = str(bullent) print(bullent) if __name__ == '__main__': bv = 'BV1Jz411b7zG' cid = get_cid(bv) bullent = get_bullet_chat(cid) wold_count(bullent)