对数据统计部分进行性能分析

main
p6fxi93qh 2 months ago
parent fc937c5a0d
commit aad2ee8502

@ -0,0 +1,35 @@
import cProfile
import os
from getdm import get_videos_url,get_danmu,get_web_url
def getalldm(videos_url,savepath): #从所有视频中获得弹幕
with open(savepath, 'w', encoding='utf-8') as file: # 打开文件准备写入
for item in videos_url :
res = get_danmu(item)
for result in res :
file.write(f"{result}\n ")
file.write("\n")
def profile_getalldm():
# 获取所有页面的 URL
pages = 10
keyword = '2024巴黎奥运会'
webs_url = get_web_url(keyword, pages)
# 获取所有视频的 URL
videos_url = []
for item in webs_url:
now = get_videos_url(item)
videos_url.extend(now) #
# 获取所有视频的弹幕
res_dir = os.path.join(os.getcwd(), 'res')
if not os.path.exists(res_dir):
os.makedirs(res_dir)
file_name = "total_final.txt"
savepath = os.path.join(res_dir, file_name)
os.makedirs(os.path.dirname(savepath), exist_ok=True)
getalldm(videos_url, savepath)
if __name__ == '__main__':
cProfile.run('profile_getalldm()', 'profile_results.txt')
Loading…
Cancel
Save