You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.1 KiB
36 lines
1.1 KiB
2 months ago
|
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')
|
||
|
|