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.

37 lines
2.3 KiB

import requests
import json
# 定义API的URL地址模板
url_template = 'https://api.bilibili.com/x/player/pagelist?aid={}'
# 设置请求头
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0',
'cookie': 'buvid3=C1C1F447-BE4B-207B-2957-83F2A71759A059661infoc; b_nut=1702126959; i-wanna-go-back=-1; b_ut=7; _uuid=A1D1B10B10-2CF10-E524-9184-1071108C67B4E1064260infoc; enable_web_push=DISABLE; buvid4=5317C42D-F53F-8ADA-D1A4-10ED5A8CF36360134-023120913-; rpdid=|(u)luk)~u|l0J\'u~|kku|YkJ; buvid_fp_plain=undefined; DedeUserID=503618475; DedeUserID__ckMd5=0191b9f7decce9ef; header_theme_version=CLOSE; CURRENT_FNVAL=4048; PVID=1; FEED_LIVE_VERSION=V_DYN_LIVING_UP; CURRENT_QUALITY=80; fingerprint=494d7e3b36301c3a79f8e9874737c192; buvid_fp=494d7e3b36301c3a79f8e9874737c192; home_feed_column=5; browser_resolution=1528-738; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjY3NDUwMjAsImlhdCI6MTcyNjQ4NTc2MCwicGx0IjotMX0.eMwpvZWiFlweKrmxccHjMI_iLBtXhkjCTiGo47ZzSYo; bili_ticket_expires=1726744960; SESSDATA=83336e6b%2C1742037821%2C360f4%2A92CjAH43lV7rav7Ckt21G7pofPKHP90eY8UWnZbAt07TaYyt5UEqN4ePWE_NCr5lh3vfYSVkJoSzBzNldWOFZWUEZJZ2Y3YnY0dXZZWmllcXhUMlpDT1RhVk4xYldiZ3NRMG9XVnZpUnk4SWN6UHNLUUx3cDBsNkxUMHRHajZ2WGlkak5MVUFTX1RBIIEC; bili_jct=9406239f74c298cb8651019f52e42523; sid=7uv2rrbi; b_lsid=8BA3B5CC_191FF98AD70; bp_t_offset_503618475=978100787878035456; bsource=search_google'
}
# 打开cid.txt文件准备写入CID
with open("cid.txt", "w") as f:
# 读取id.txt文件中的ID列表
with open("id.txt", "r") as ids_file:
ids = ids_file.readlines()
# 遍历ID列表
for id in ids:
# 去除ID字符串中的换行符
id = id.strip()
# 构造API请求URL
api_url = url_template.format(id)
# 发送GET请求
response = requests.get(api_url, headers=headers)
response.encoding = 'utf-8'
# 解析JSON响应
data = json.loads(response.text)
# 提取CID
cid = data['data'][0]['cid'] # 修正此处
# 将CID写入cid.txt文件并添加换行符
f.write(f"{cid}\n")
# 打印提示信息
print("CID 已成功写入 cid.txt 文件")