parent
c1b47d5526
commit
52fb60e678
@ -1,26 +0,0 @@
|
||||
import requests
|
||||
|
||||
def get_cid_from_bv(bv_id):
|
||||
# 视频详情 API 地址
|
||||
video_url = f'https://api.bilibili.com/x/web-interface/view?bvid={bv_id}'
|
||||
|
||||
headers = {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
|
||||
}
|
||||
|
||||
# 发送请求
|
||||
response = requests.get(video_url, headers=headers)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
|
||||
# 提取 cid
|
||||
if data.get('code') == 0:
|
||||
cid = data.get('data', {}).get('cid')
|
||||
return cid
|
||||
else:
|
||||
return None
|
||||
|
||||
# 使用示例
|
||||
bv_id = 'BV1m7411e71N' # 替换为你的视频 BV 号
|
||||
cid = get_cid_from_bv(bv_id)
|
||||
print(f'CID: {cid}')
|
Loading…
Reference in new issue