如何使用python爬取b站番剧真实评分,22年当时看过网友用爬虫统计出三体的真实评分,现在好像b站更新了新的反爬,这个代码用不了了
import requests
import json
print("----------------------------------------------------------------------------------")
print("三体动画B站评分")
counts = [0, 0, 0, 0, 0]
longs = 0
longt = 0
cursor = 0
while True:
res = requests.get("https://api.bilibili.com/pgc/review/long/list?media_id=4315402&ps=20&sort=0&cursor={}".format(cursor))
data = json.loads(res.text)
for i in data["data"]["list"]:
longs += i["score"]//2
longt += 5
counts[i["score"]//2-1] += 1
if data["data"]["next"] != 0:
cursor = int(data["data"]["next"])
else:
break
print("长评总星数:{},总长评数{},长评平均:{:.1f}".format(longs, longt//5, longs / longt * 10))
shorts = 0
shortt = 0
cursor = 0
while True:
res = requests.get("https://api.bilibili.com/pgc/review/short/list?media_id=4315402&ps=20&sort=0&cursor={}".format(cursor))
data = json.loads(res.text)
for i in data["data"]["list"]:
shorts += i["score"]//2
shortt += 5
counts[i["score"]//2-1] += 1
if data["data"]["next"] != 0:
cursor = int(data["data"]["next"])
else:
break
print("短评总星数:{},总短评数{},短评平均:{:.1f}".format(shorts, shortt//5, shorts / shortt * 10))
print("总星数:{},平均:{:.1f}".format(shorts + longs , (shorts+longs) / (shortt+longt) * 10))
for i in range(1,6):
print("{}星人数{},占比{:.2f}%".format(i, counts[i-1], counts[i-1]/(longt+shortt)*500))
print("----------------------------------------------------------------------------------")
现在好像不行了,想问有没有其他办法,更新下这个代码,我想爬取一下mujica的真实评分