如何解决Pytube“ YouTube”对象没有属性“过滤器”
我正尝试使用pytube从Youtube下载,首先我遇到一个常见问题,我认为这是模块本身的问题,因此我使用github对其进行了升级,然后此代码中发生了另一个错误:
#importing the module
from pytube import YouTube
#where to Save
save_path = "E:\Mohamed's sessions\pytube"
#link of the youtube video to be downloaded
link = "https://www.youtube.com/watch?v=w9TcErzdoTg"
#creating an object using YouTube which was imported beofre
yt = YouTube(link) # now this yt is an object created by the class youtube and has the attribute link
#filtering out all the files with mp4 extinsion
mp4files = yt.filter("mp4")
#setting the video name
yt.set_filename("Reiner and Bertholdt Transformation scene")
#get the video with the extension and resolution passed in the get() function
d_video = yt.get(mp4files[-1].extension,mp4files[-1].resolution)
try:
#downloading the video
d_video.download(save_path)
except:
print("Some Error!")
print('Task Completed!')
错误标题为: AttributeError:“ YouTube”对象没有属性“过滤器” 我该如何解决?
解决方法
这里是一个更简单的代码,可以解决您遇到的问题:
from pytube import YouTube
link = "https://www.youtube.com/watch?v=w9TcErzdoTg"
yt = YouTube(link)
try:
yt.streams.filter(progressive = True,file_extension = "mp4").first().download(output_path = "E:\Mohamed's sessions\pytube",filename = "Reiner and Bertholdt Transformation scene")
except:
print("Some Error!")
print('Task Completed!')
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。