You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python下载YouTube视频时遇AttributeError:'YouTube'对象无'get_videos'属性

Fixing AttributeError: 'YouTube' object has no attribute 'get_videos' in pytube

Hey there! That error pops up because the get_videos() method was removed in newer versions of pytube. The library updated its API a while back, so your code just needs a quick tweak to match the current way of accessing video streams.

Here's how to fix it:

Instead of get_videos(), you'll use the streams attribute of the YouTube object. This attribute lets you access all available video and audio streams for your target video, with options to filter or select exactly what you need.

Updated Code Example:

import pytube

# Replace with your actual YouTube video URL
link = "https://www.youtube.com/watch?v=your_video_id"
yt = pytube.YouTube(link)

# Option 1: List all available streams (includes different resolutions/formats)
# For older pytube versions:
all_streams = yt.streams.all()
# For latest pytube versions (where `all()` is deprecated):
all_streams = list(yt.streams)

# Option 2: Filter for progressive streams (video + audio combined in one file)
progressive_streams = yt.streams.filter(progressive=True)

# Option 3: Download a specific resolution directly
# Download 720p video if it's available
yt.streams.get_by_resolution("720p").download()

# Or download the highest available resolution automatically
yt.streams.get_highest_resolution().download()

Quick Tips:

  • Progressive streams are perfect if you want a single file with both video and audio. If you need separate high-quality audio and video files, use yt.streams.filter(only_audio=True) or only_video=True, then merge them later with a tool like FFmpeg.
  • Always make sure you're using the latest version of pytube—run pip install --upgrade pytube if you haven't already, to avoid API mismatch issues.

内容的提问来源于stack exchange,提问作者user9594573

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 07:33:55