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對應(yīng)一個視頻(aid來源:bilibili某個視頻頁抒和,打開源碼即可搜索到當(dāng)前頁面視頻對應(yīng)的aid參數(shù))
1.voidplay_url參數(shù)為視頻aid膳沽,返回對應(yīng)視頻的詳細(xì)信息汗菜;
- voidplaydetail_url參數(shù)為avid(等同aid),cid(對應(yīng)voidplay_url請求返回的cid)挑社,返回?cái)?shù)據(jù)responseObject[@"data"][@"durl"][0][@"url"]]為視頻流地址