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