python - 如何使用 Python 下载 youtube 视频?

标签 python pytube

<分区>

我正在尝试使用它在 python 中的 url 下载 YouTube 视频,但我得到:

urllib.error.HTTPError: HTTP Error 403: Forbidden

我正在使用 Python 库 pytube 下载 youtube 视频。这是我的代码:

#importing the module 
from pytube import YouTube 
  
my=YouTube("https://www.youtube.com/watch?v=R4em3LKQCAQ").streams.first()
my.download()

我收到如下错误信息

raise HTTPError(req.full_url, code, msg, hdrs, fp)

urllib.error.HTTPError: HTTP Error 403: Forbidden

最佳答案

2022 年更新 我不再维护 mhyt 库。

你可以尝试 youtube_dl 选项:

安装:

pip install youtube_dl
# or for faster download and more improvements: 
#pip install yt-dlp

并使用:

from youtube_dl import YoutubeDL
# or for yt_dlp: 
# from yt_dlp import YoutubeDL
with YoutubeDL() as ydl:
    ydl.download(["https://www.youtube.com/watch?v=R4em3LKQCAQ"])

原始答案:

I have created a library that makes it.

To install:

bash $ pip install mhyt

And use it like:

from mhyt import yt_download
yt_download("https://www.youtube.com/watch?v=R4em3LKQCAQ","download.mp4")

关于python - 如何使用 Python 下载 youtube 视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56617247/

相关文章:

python - 使用 Python 图像库 (PIL) 绘制抗锯齿线

python - 错误: MySQL_python: does not support sharing connections between threads

python - 类字段/实例变量的 Pycharm 类型提示

python - 导入错误 : cannot import name 'quote'

python - 如何使用 pytube 从 Youtube 播放列表下载中间视频

python - 从管道 Python 读取

python - 在 HPaned 问题中调整 gtk TreeView 的大小

python - ffmpeg_extract_subclip 函数和moviepy字符串输出错误

python - 使用 Pytube 从 YouTube 下载播放列表

python - 使用pytube同时下载多个视频