Update bvid_search.py

main
pff5ls68k 2 months ago
parent 54ac25b328
commit e4c6b50078

@ -1,45 +1,44 @@
import requests import requests
def get_video_ids(api_urls): def get_video_ids(api_urls):
headers = { headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0',
'Cookie': "buvid3=A208D8C8-62E0-8A2C-49DE-97075EC9AFF347900infoc; b_nut=1709605247; CURRENT_FNVAL=4048; _uuid=6B1712B5-E56D-39CF-2F4F-1109679B2275450779infoc; buvid4=56D339AE-65A3-9EB3-637F-1C6844E511FF48608-024030502-XZT8dGJQQGvpxEW%2FgPNaOA%3D%3D; rpdid=|(u))kkYu|Yk0J'u~|mY|lklu; DedeUserID=506426443; DedeUserID__ckMd5=3fc44628b47de972; enable_web_push=DISABLE; FEED_LIVE_VERSION=V8; header_theme_version=CLOSE; fingerprint=0eaa6f4de3c8e4fbb7ac2f6b2dbeeaf2; buvid_fp_plain=undefined; buvid_fp=0eaa6f4de3c8e4fbb7ac2f6b2dbeeaf2; LIVE_BUVID=AUTO2817161348895068; CURRENT_QUALITY=80; SESSDATA=c20b1ba2%2C1741679244%2C9fa32%2A91CjDmAy9_jeDRbsRQaSuk5MkfKaRAaVej6SEgP7hWsXGVhV2wJNMxhHCTMRpuUFBL-48SVlV2TDFTZk5Md2NCR2Fxc3doVDFtTGIycU1pd0dGcGt0UC1kLUZoVURHQTJmNGZVb1IxVlk5Zk4yRTl5cFdOMUpJN1JFNy1UZXpMWmQ5bzZjcWdQRzRBIIEC; bili_jct=cc779de17c4fba7ff039ca3e8573ad3d; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjYzODY0NzIsImlhdCI6MTcyNjEyNzIxMiwicGx0IjotMX0.X7nq8XaGsaZS0lUB42-EyN2Q4hPwUkSc4a9pGNkrqZY; bili_ticket_expires=1726386412; PVID=1; home_feed_column=5; browser_resolution=1699-943; sid=4mrblyq6; bp_t_offset_506426443=976262979962011648; b_lsid=691F191E_191E6B279BF" 'Cookie': "buvid3=A208D8C8-62E0-8A2C-49DE-97075EC9AFF347900infoc; b_nut=1709605247; CURRENT_FNVAL=4048; _uuid=6B1712B5-E56D-39CF-2F4F-1109679B2275450779infoc; buvid4=56D339AE-65A3-9EB3-637F-1C6844E511FF48608-024030502-XZT8dGJQQGvpxEW%2FgPNaOA%3D%3D; rpdid=|(u))kkYu|Yk0J'u~|mY|lklu; DedeUserID=506426443; DedeUserID__ckMd5=3fc44628b47de972; enable_web_push=DISABLE; FEED_LIVE_VERSION=V8; header_theme_version=CLOSE; fingerprint=0eaa6f4de3c8e4fbb7ac2f6b2dbeeaf2; buvid_fp_plain=undefined; buvid_fp=0eaa6f4de3c8e4fbb7ac2f6b2dbeeaf2; LIVE_BUVID=AUTO2817161348895068; CURRENT_QUALITY=80; SESSDATA=c20b1ba2%2C1741679244%2C9fa32%2A91CjDmAy9_jeDRbsRQaSuk5MkfKaRAaVej6SEgP7hWsXGVhV2wJNMxhHCTMRpuUFBL-48SVlV2TDFTZk5Md2NCR2Fxc3doVDFtTGIycU1pd0dGcGt0UC1kLUZoVURHQTJmNGZVb1IxVlk5Zk4yRTl5cFdOMUpJN1JFNy1UZXpMWmQ5bzZjcWdQRzRBIIEC; bili_jct=cc779de17c4fba7ff039ca3e8573ad3d; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjYzODY0NzIsImlhdCI6MTcyNjEyNzIxMiwicGx0IjotMX0.X7nq8XaGsaZS0lUB42-EyN2Q4hPwUkSc4a9pGNkrqZY; bili_ticket_expires=1726386412; PVID=1; home_feed_column=5; browser_resolution=1699-943; sid=4mrblyq6; bp_t_offset_506426443=976262979962011648; b_lsid=691F191E_191E6B279BF"
} }
all_video_ids = [] all_video_ids = []
cnt = 0 # 设定计数器
for page in range(1, 22): cnt = 0
# print(api_url) # 暴力查找
api_url = api_urls + str(page) for page in range(1, 22):
# print(api_url) # 执行翻页操作
response = requests.get(api_url, headers=headers) api_url = api_urls + str(page)
response.encoding = 'utf-8' # 获取Datas
Json = response.json() response = requests.get(api_url, headers=headers)
# print(Json) response.encoding = 'utf-8'
# print(Json['data']) Json = response.json()
Datas = Json['data']['result'] Datas = Json['data']['result']
for Data in Datas: for Data in Datas:
try: # 通过try except跳过B站设置的断点
# print(Data) try:
bvids = Data['bvid'] bvids = Data['bvid']
print(bvids) print(bvids)
with open("bvid.txt", mode='a', encoding='utf-8') as f: with open("bvid.txt", mode='a', encoding='utf-8') as f: # 执行写入操作
f.write(bvids + '\n') f.write(bvids + '\n')
cnt += 1 cnt += 1
if (cnt == 300): if (cnt == 300):
break break
except: except:
continue continue
if (cnt == 300): if (cnt == 300):
break break
# print(bvids) # print(bvids)
return 1 return 1
# API URLs # API URLs
api_urls = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword=巴黎奥运会&page=' api_urls = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword=巴黎奥运会&page='
video_ids = get_video_ids(api_urls) video_ids = get_video_ids(api_urls)
# save_video_ids_to_file(video_ids, 'bvid.txt')

Loading…
Cancel
Save