import requests
import json
if __name__ == '__main__':
voidplay_url = 'https://api.bilibili.com/x/web-interface/view'
voidplaydetail_url = 'https://api.bilibili.com/x/player/playurl?callback=callbackfunction&page=1&platform=html5&quality=3&vtype=mp4&type=jsonp'
headers = {"User-Agent":" Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36"}
archives_list = ["813877653","729015095","301586032","814004679","984022887","344124067","686587760","601619247","686532500","686586022"]
item_list = []
for archives in archives_list:
item = {}
param = {'aid':archives}
response = requests.get(voidplay_url,param)
html_str = response.content.decode()
# print('html_str____'+html_str)
html_dic = json.loads(html_str)
print(html_dic)
item['bvid'] = html_dic['data']['bvid']
item['aid'] = html_dic['data']['aid']
item['cid'] = html_dic['data']['cid']
item['duration'] = html_dic['data']['duration']
item['pic'] = html_dic['data']['pic']
item['title'] = html_dic['data']['title']
item['desc'] = html_dic['data']['desc']
item['pubdate'] = html_dic['data']['pubdate']
item['ctime'] = html_dic['data']['ctime']
item['author'] = html_dic['data']['owner']['name']
item['favorite'] = html_dic['data']['stat']['favorite']
item['view'] = html_dic['data']['stat']['view']
item_list.append(item)
print(item_list)
with open('zuixin.json','a',encoding='utf-8') as f:
f.write('[')
for item in item_list:
f.write(json.dumps(item,ensure_ascii=False,indent=2))
f.write(',')
f.write(']')
print('保存成功')
archives_list为视频的aid信息列表,每个aid对应一个视频(aid来源:bilibili某个视频页,打开源码即可搜索到当前页面视频对应的aid参数)
1.voidplay_url参数为视频aid,返回对应视频的详细信息;
- voidplaydetail_url参数为avid(等同aid),cid(对应voidplay_url请求返回的cid),返回数据responseObject[@"data"][@"durl"][0][@"url"]]为视频流地址