在接口https://api.bilibili.com/x/web-interface/ranking/v2?rid=0&type=all中,哔哩哔哩给出了即时的排名前100位的视频信息,如图所示 在当前还是可以访问的,这个接口。对100条视频进行获取和转换到excel中如下,对pandas库稍有理解的读者即可明白,
import pandas as pd
import json
import requests
r = requests.get("https://api.bilibili.com/x/web-interface/ranking/v2?rid=0&type=all")
jsonData = json.loads(r.text)
author = []
view = []
danmu = []
coins = []
share = []
like = []
score = []
favor = []
reply = []
rank = []
pubdate = []
for i in range(0, 100):
videoData = jsonData['data']['list'][i]
score.append(videoData['score'])
author.append(videoData['owner']['name'])
pubdate.append(videoData['pubdate'])
videoStat = videoData['stat']
danmu.append(videoStat['danmaku'])
view.append(videoStat['view'])
rank.append(videoStat['his_rank'])
reply.append(videoStat['reply'])
favor.append(videoStat['favorite'])
coins.append(videoStat['coin'])
share.append(videoStat['share'])
like.append(videoStat['like'])
outfile = pd.DataFrame(
{"author": author, "rank": rank, "score": score, "view": view, "coins": coins, "favorite": favor,
"reply": reply, "danmu": danmu, "pubdate": pubdate})
outfile.to_csv("bilibili.csv")
这个接口可能随时不可用,所以本文可能不具有持久性。
|