如何解决使用pytube下载youtube视频时出现属性错误
我已经使用Python一段时间了,我决定使用pytube从Youtube下载视频,但是当我尝试下载视频时,出现属性错误。
import pytube
from pytube import *
def run():
try:
down_dir = "C:/Users/ASUS/Desktop/python projects/youtube_video_installer"
video_link = input("enter video url")
res_selected = input("enter required res")
youtube = YouTube(video_link)
title = youtube.title
print("Now downloading," + str(title))
video = youtube.streams.get_by_resolution(res_selected)
# file_size = "FileSize : " + str(round(video.filesize / (1024 * 1024))) + "MB"
print(title)
if down_dir is not None:
video.download(output_path=down_dir,filename=str(title))
else:
video.download()
print("Download complete," + str(title))
except Exception as e:
print("ErrorDownloadVideo | " + str(video_link))
run()
当我设置视频= youtube.streams.first()时 它可以工作,但是每当我使用.get_by_itag或.get_by_resolution指定视频时,都会出现此错误
File "C:/Users/ASUS/Desktop/python projects/youtube_video_installer/console.py",line 31,in <module>
run()
File "C:/Users/ASUS/Desktop/python projects/youtube_video_installer/console.py",line 22,in run
video.download(output_path=down_dir,filename=str(title))
AttributeError: 'NoneType' object has no attribute 'download'
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。