我正试图在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
这一行出错。我不知道为什么会失败。
此代码与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")