使用 Chrome调试控制台 下载YouTube 的字幕

3 min read

使用 Chrome调试控制台 下载YouTube 的字幕

  • 点击页面上的CC按钮,在控制台的网络请求页面加载到如下的url
https://www.youtube.com/api/timedtext
  • 右键链接copy 为 fetch ,在控制台复制链接,拼接如下的js代码
fetch("https://www.youtube.com/api/timedtext?v=yyUHQIec83I&caps=asr&xoaf=5)..then(async res => {
    const content = await res.json()
    const arr = []
    content.events.forEach(item => {
        if (item.segs) {
            arr.push(item.segs.map(i => i.utf8).join(''))
        }

    });
    console.log(arr.join(""));
}
)