【问题标题】:Unable to download youtube videos from shutil Python无法从 shutil Python 下载 youtube 视频
【发布时间】:2020-04-11 03:10:48
【问题描述】:

我想使用 Python 下载 YouTube 视频。我使用此代码来抓取图像并且效果很好。但是,当我将此图像链接更改为 youtube 视频时,它会保存文件,但会出错损坏 mp4 文件。 知道我做错了什么吗?

这是我的代码:

import requests
import shutil
import time
import urllib

video_url = r"https://i.ytimg.com/vi/hoNb6HuNmU0/hq720.jpg?sqp=-oaymwEZCNAFEJQDSFXyq4qpAwsIARUAAIhCGAFwAQ==&rs=AOn4CLBTdEdTL4oiRB_L8AJITd9xzfllMA"
resp = requests.get(video_url, stream=True)
local_file = open(r'C:/users/intel/desktop/local_image.mp4', 'wb')
resp.raw.decode_content = True
shutil.copyfileobj(resp.raw, local_file)
del resp

您的任何帮助将不胜感激...

【问题讨论】:

    标签: python python-3.x beautifulsoup python-requests shutil


    【解决方案1】:

    你的方法行不通。

    查看https://github.com/ytdl-org/youtube-dl 了解下载 YouTube 视频的正确方法。

    【讨论】:

      猜你喜欢
      • 2012-09-07
      • 2011-02-10
      • 2012-12-21
      • 2019-11-23
      • 1970-01-01
      • 2010-11-08
      • 1970-01-01
      • 2014-05-25
      • 1970-01-01
      相关资源
      最近更新 更多