1 Star 1 Fork 0

Ty/Bilibili-Downloader-Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
bilibili.py 1.63 KB
一键复制 编辑 原始数据 按行查看 历史
Ty 提交于 4年前 . bilibili.py
# -*- 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()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/yqssss/bilibili-downloader-python.git
git@gitee.com:yqssss/bilibili-downloader-python.git
yqssss
bilibili-downloader-python
Bilibili-Downloader-Python
master

搜索帮助