【问题标题】:I found a Key error of 'start' when using pytube.caption使用 pytube.caption 时发现“开始”的关键错误
【发布时间】:2021-10-14 00:29:29
【问题描述】:

我正在尝试通过 pytube 下载 Youtube 字幕。

一切都很好,我设法通过 xml_captions 下载了视频及其标题。

但是,当我尝试将其转换为 .srt 格式时,我遇到了一个关键错误。

---> 83             start = float(child.attrib["start"])  
KeyError: 'start'

我不知道出了什么问题。 我的代码是

pip install pytube
from pytube import YouTube
# misc``
import os
import shutil
import math
import datetime
video=YouTube('https://www.youtube.com/watch?v=xxydY73V9bQ')
caption = video.captions['a.en']
caption.xml_captions
srt_format = caption.xml_caption_to_srt(caption.xml_captions)

【问题讨论】:

  • 错误似乎很明显:child.attrib 字典中没有 start 键。
  • 该行不在您发布的代码中。你还没有展示你是如何设置child的。

标签: python keyerror pytube


【解决方案1】:

如果 sill 相关:tt 似乎 YouTube 已经改变了字幕的处理方式。 Here's a discussion 提供可能的解决方案。

【讨论】:

    猜你喜欢
    • 2020-11-13
    • 2020-10-26
    • 1970-01-01
    • 2011-03-11
    • 1970-01-01
    • 2022-09-22
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多