python - 在 YouTube 上搜索并返回 n 个链接
问题描述
我正在尝试从 youtube 下载某些给定关键字的视频。现在我正在使用这个代码 -
import urllib.request
import re
search_keyword="race+car"
html = urllib.request.urlopen("https://www.youtube.com/results?search_query=" + search_keyword)
video_ids = re.findall(r"watch\?v=(\S{11})", html.read().decode())
for i in range(0,len(video_ids)):
#print("https://www.youtube.com/watch?v=" + video_ids[i])
youtube_video_url = "https://www.youtube.com/watch?v=" + video_ids[i]
try:
yt_obj = YouTube(youtube_video_url)
filters = yt_obj.streams.filter(progressive=True, file_extension='mp4')
filters.get_highest_resolution().download()
print('Video Downloaded Successfully')
except Exception as e:
print(e)
print(len(video_ids))
这现在为我下载了 30 个视频。有没有办法下载我想要的任意数量的视频,比如 100 个或 1000 个?
解决方案
推荐阅读
- java - 捕获方法及其主体的正则表达式
- python - 创建后锁定语音频道(Discord Python)
- javascript - 将图像添加到工作表页眉/页脚 - Office JS - Excel
- azure - 当我尝试 git push 时出现此错误 | [ErrorException]:作曲家失败
- java - 使用 OpenJDK 时默认运行哪个 JVM?
- mongodb - 计算行数并仅获取 MongoDB 中的最后一行
- flutter - 带有 switch 的观察者:主体可能正常完成,导致返回“null”,但返回类型可能是不可为空的类型
- assembly - 是否有可能制作一个永远编写自己的汇编程序?
- node.js - express fileupload 包的路径问题
- python - 在我基于研究论文的 CNN 模型上获得可怕的准确性:~ 5%