【问题标题】:problem in printing a youtube title using python使用 python 打印 youtube 标题的问题
【发布时间】:2021-06-27 13:17:11
【问题描述】:

这是我的代码

from pytube import YouTube
a=YouTube("https://www.youtube.com/watch?v=vvpb8IdDZZI")
#to print title 
print("\n")
print("******************title*****************")
print("the title is:"+a.title)

错误是

raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found

但是网址存在!!!我已经从浏览器本身复制了这个网址 我也升级了我的pytube

【问题讨论】:

  • 您确定这是无效的代码吗?它对我有用。
  • 尝试更新pytube模块here

标签: python visual-studio-code error-handling


【解决方案1】:

我没有用过 pytube,但是 pafy 模块对我来说很好用,你可以通过编写命令“pip install pafy”来安装它。您的代码应如下所示:

import pafy

url = "https://www.youtube.com/watch?v=vvpb8IdDZZI"
video = pafy.new(url)

#to print title 
print("\n")
print("******************title*****************")
print("the title is:" + video.title)

您可以在此处找到有关 pafy 模块的更多信息:https://pypi.org/project/pafy/

【讨论】:

    【解决方案2】:

    尝试使用以下方式安装 pytube:

    pip install git+https://github.com/ssuwani/pytube 
    

    而且正式版也解决了这个问题。

    您可以从here获取详细信息。

    【讨论】:

    • @Aravind Bhat 你好朋友,有用吗?
    猜你喜欢
    • 2019-12-09
    • 1970-01-01
    • 2022-01-27
    • 1970-01-01
    • 1970-01-01
    • 2013-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多