【问题标题】:Get transcript of youtube video获取 youtube 视频的成绩单
【发布时间】:2020-07-26 07:56:08
【问题描述】:

我想在 YouTube 上获取视频的文字记录,但我卡住了 这就是我所拥有的

Sub ANew()
    Dim doc As HTMLDocument, ie As Object, p As Integer, i As Integer
    Set ie = CreateObject("InternetExplorer.Application")
    With ie
        .Visible = True
        
            .Navigate "https://www.youtube.com/watch?v=CkzK1nfWoeA"
            Do: DoEvents: Loop Until ie.readyState = READYSTATE_COMPLETE
            Set doc = ie.document
            
            While ie.readyState <> 4: DoEvents: Wend
            Debug.Print doc.querySelectorAll("div .ytd-transcript-body-renderer")(1).innerHTML
            

        ie.Quit
    End With
End Sub

我在Debug.Print doc.querySelectorAll("div .ytd-transcript-body-renderer")(1).innerHTML 这一行遇到了错误。我不知道为什么会失败。

【问题讨论】:

  • Next p在哪里?
  • 我删除了循环,因为这与代码无关。
  • 当我查看网站的源代码时,没有任何 ytd-transcript-body-renderer css 类的元素?
  • 所以这在每个浏览器中可能不同。实际上,我使用 Chrome 而不是 IE 检查了该页面,因为 IE 因使用开发人员工具而损坏。

标签: excel vba youtube screen-scraping


【解决方案1】:

此代码适用于 Python,但希望使用 VBA 找到解决方案

from youtube_transcript_api import YouTubeTranscriptApi
import json
import pandas

data = YouTubeTranscriptApi.get_transcript('CkzK1nfWoeA')
with open('Transcript.json', 'w') as outfile:
    json.dump(data, outfile)
pandas.read_json("Transcript.json").to_excel("Output.xlsx")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-20
    • 1970-01-01
    • 2015-09-02
    • 2012-04-15
    • 2013-03-23
    相关资源
    最近更新 更多