【问题标题】:Pytube: AttributeError: 'str' object has no attribute 'author'Pytube:AttributeError:'str'对象没有属性'author'
【发布时间】:2021-09-09 18:30:41
【问题描述】:

我为 YouTube 下载创建了这段代码,但它给了我这个错误:

import pytube
from pytube import YouTube

while True:
    url = input("Enter the video link: ")

    print("Uploading the video...")
    print("Authot: " + url.author)
   
    pytube.YouTube(url).streams.get_highest_resolution().download()
    print("Video scaricato")

    loop = input("\nDo you want to continue using the program ?: ")
    if loop == "Yes" or loop == "yes":
        continue
    else:
        break

AttributeError: 'str' 对象没有属性 'author'

【问题讨论】:

    标签: python youtube attributeerror pytube


    【解决方案1】:

    变量url 将保存用户输入的任何值。因此,这将是str 类型的值。因此无法做到url.author

    【讨论】:

      【解决方案2】:

      url是一个字符串,你要从pytube对象中获取作者

      import pytube
      from pytube import YouTube
      
      while True:
          url = input("Enter the video link: ")
      
          print("Uploading the video...")
          print("Authot: " + pytube.YouTube(url).author)
      
          pytube.YouTube(url).streams.get_highest_resolution().download()
      
          print("Video scaricato")
      
          loop = input("\nDo you want to continue using the program ?: ")
          if loop == "Yes" or loop == "yes":
              continue
          else:
              break
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-12-31
        • 2021-12-07
        • 2021-05-08
        • 2022-08-22
        • 1970-01-01
        • 1970-01-01
        • 2015-09-11
        • 2016-09-20
        相关资源
        最近更新 更多