收集综合排名前300的视频弹幕

main
p6fxi93qh 5 months ago
parent eba4d14f29
commit f84f95ec88

@ -0,0 +1,39 @@
#收集综合排名前300的视频弹幕
#from geturl import GetVideoURL
import requests
import sys
import os
import re
import time
from getdm import get_videos_url,get_danmu
keyword = '2024巴黎奥运会'
res = get_videos_url(keyword,10)
res_dir = os.path.join(os.getcwd(), 'res')
if not os.path.exists(res_dir):
os.makedirs(res_dir)
# 指定输出文件"total300.txt"
file_name = "total300_3.txt"
file_path = os.path.join(res_dir, file_name)
count = 0
#连续写入
with open(file_path, 'w', encoding='utf-8') as file: # 打开文件准备写入
for video_id in res:
danmu = get_danmu(video_id)
# 写入这是第几个视频的弹幕
count += 1
#file.write(f"这是第{count}个视频的弹幕===================:\n")
for item in danmu:
file.write(f"{item} ")
file.write("\n")
print(f"{count}个视频的弹幕已写入")
time.sleep(5) # 等待6秒
Loading…
Cancel
Save