代码拉取完成,页面将自动刷新
# -*- coding:utf-8 -*-
import requests
import json
import re
class Bili(object):
def __init__(self, bv):
self.bv = bv
def get_url(self):
base_url = "https://m.bilibili.com/video/" + str(self.bv)
headers = {
"user-agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"
}
try:
response = requests.get(url=base_url, headers=headers, timeout=5)
if response.status_code == 200:
pattern = re.compile("options = \{(.*?)\}", re.S)
# res ="{"+ re.findall(pattern,response.text)[0]+"}"
res = re.findall(pattern, response.text)[0]
aid = re.findall("aid: (.*?),", res)[0]
cid = re.findall("cid: (.*?),", res)[0]
readyDuration = re.findall("readyDuration: (.*?),", res)[0]
bvid = re.findall("bvid: '(.*?)',", res)[0]
readyPoster = re.findall("readyPoster: '(.*?)',", res)[0]
readyVideoUrl = re.findall("readyVideoUrl: '(.*?)',", res)[0]
rows = {
"aid": aid,
"bvid": bvid,
"cid": cid,
"readyPoster": "https:" + readyPoster,
"readyVideoUrl": "https:" + readyVideoUrl,
"readyDuration": readyDuration,
}
print(json.dumps(rows))
except Exception as e:
print(e)
bv = input("请输入要解析的bv号")
if __name__ == "__main__":
bili = Bili(bv)
bili.get_url()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。