gpt4 book ai didi

python-3.x - 使用python脚本下载YouTube视频

转载 作者:行者123 更新时间:2023-12-03 06:12:56 24 4
gpt4 key购买 nike

我有这个脚本来下载youtube视频

from pytube import YouTube

yt = YouTube('https://www.youtube.com/watch?v=kAGacI3JwS4')
#yt.title
#yt.thumbnail_url
#yt.streams.all()
stream = yt.streams.first()
#stream
stream.download('C:\\Users\')

但是我希望这是根据用户提示方式发生的。所以它应该要求用户输入网址,然后从那里进行进一步下载视频,所以我确实喜欢这样
>>> pk=input("Enter the url:")

Enter the url:https://www.youtube.com/watch?v=GhklL_kStto
>>> pk

'https://www.youtube.com/watch?v=GhklL_kStto'
>>> pk.title

<built-in method title of str object at 0x02362770>
>>> pk.stream()
Traceback (most recent call last):
File "<pyshell#44>", line 1, in <module>
>>pk.stream()
AttributeError: 'str' object has no attribute 'stream'

所以这就是错误所在。有人可以帮助我解决这个问题吗?

感谢您的支持!

最佳答案

我希望这个答案不会太晚,但是问题在于pk是一个字符串,因为:

pk=input("Enter the url:")

此处将 pk辅助为一个字符串(也就是您输入的任何内容),因此无法创建相关的 Youtube对象。

输入 pk.title时得到的描述证明它是 str对象的内置方法。您甚至都没有为其创建 YouTube方法而创建 stream对象。

您可以这样解决:
url = input("Enter the url:")
pkl = YouTube(url)
pkl.stream()

希望这可以帮助

关于python-3.x - 使用python脚本下载YouTube视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48647147/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com