Update bvid_search.py

main
pff5ls68k 2 months ago
parent 54ac25b328
commit e4c6b50078

@ -8,23 +8,23 @@ def get_video_ids(api_urls):
} }
all_video_ids = [] all_video_ids = []
# 设定计数器
cnt = 0 cnt = 0
# 暴力查找
for page in range(1, 22): for page in range(1, 22):
# print(api_url) # 执行翻页操作
api_url = api_urls + str(page) api_url = api_urls + str(page)
# print(api_url) # 获取Datas
response = requests.get(api_url, headers=headers) response = requests.get(api_url, headers=headers)
response.encoding = 'utf-8' response.encoding = 'utf-8'
Json = response.json() Json = response.json()
# print(Json)
# print(Json['data'])
Datas = Json['data']['result'] Datas = Json['data']['result']
for Data in Datas: for Data in Datas:
# 通过try except跳过B站设置的断点
try: try:
# print(Data)
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):
@ -42,4 +42,3 @@ def get_video_ids(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