You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
726 B
26 lines
726 B
3 months ago
|
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}')
|