如何在'查看页面源之间的差异' and document.queryselector(“ html&quot”)。innerhtml?
我想从此YouTube页面提取字幕( br> 通过“查看页面源”查找时,我找到了 timedtext 。
但是当我通过JavaScript控制台搜索时,不是。它找不到:
document.querySelector("html").innerHTML.match("timedtext")
但是,对于 this 其他YouTube页面,它实际上确实可以使用。
差异如何以及如何解决?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
,如果要使用以下方式提取字幕,请考虑搜索具有
ytinitialdata
variable = action = variable =这是具有的脚本标签定时文字的URL。我无法分辨出区别,但是,我假设一旦加载页面后,JavaScript代码注入HTML代码。
粘贴线之后,您可以在评论:
我以可用语言的时间获得了定时式。不过,请记住,可能并非所有视频都具有自动生成的字幕 -
那个示例,我没有得到字幕,所以我认为检查页面的源代码不适合所有视频。
As I commented, if you want to extract the subtitles using this way, consider instead search for the script tag that has the
ytInitialData
variable = that's the one that has the url of the timedtext.I can't tell the difference, but, I assume the javascript code injects the HTML code once the page is loaded.
After pasting the line you share in your comment:
I got the timedtexts in the available languages. Keep in mind, though, probably not all videos has auto-generated captions - example
In that example, I didn't get the captions, so, I don't think that inspecting the source code of the page works for all videos.