获取动态渲染网页的 DOM

发布于 2024-10-08 09:55:02 字数 81 浏览 0 评论 0原文

是否可以通过编程方式获取动态渲染网页的结果 DOM?即编写浏览器脚本来加载 URL、渲染页面(使用 javascript 等)并输出生成的 DOM。

Is it possible to programmatically get the resulting DOM of a dynamically rendered webpage? I.e. scripting the browser to load a URL, render the page (using javascript etc) and outputting the resulting DOM.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灼痛 2024-10-15 09:55:02

是的,如果您获得对 MSHTML.IHTMLDocument2 的引用,例如将 hDoc 声明为这样,您将获得智能感知来帮助您循环遍历该文档中的项目和元素。请记住,引用是实时的,这意味着,通过任何方式(JavaScript)对 document 对象(页面)所做的任何更改,或者您对页面引用所做的更改,都将更新并显示在页面,您将能够通过访问所需的元素来查询和检索新值。当然,当您从那里访问链接时,下一页的 DOM 将是 LIVE DOM。

如果您有任何具体问题,请告诉我,我会帮助您。我希望我也正确理解了你的问题。

示例:

Dim hDoc As IHTMLDocument2

Set hDoc = WebBrowser1.Document

For i = 0 to hDoc.All.length - 1
  MsgBox hDoc.All(i).tagName & ": OuterHTML: " & hDoc.All(i).outerHTML
Next i

这将向您显示页面上每个元素的 tagName 和实际 HTML(实时)。

Yes, if you get a reference to MSHTML.IHTMLDocument2 say, declare hDoc as this, you will get intellisense to help you loop through the items and elements in that document. Remember, the reference is LIVE, meaning, any changes that are made to the document object (page) via any means, JavaScript, or changes you make with your page reference, will be updated and displayed on the page, and you will be able to query and retrieve the new values by get accessing the elements you need. Ff course, when you visit a link from there on, the next page's DOM will be the LIVE DOM.

If you have any specific questions, let me know and I will help you out. I'm hoping I understood your question correctly also.

Example:

Dim hDoc As IHTMLDocument2

Set hDoc = WebBrowser1.Document

For i = 0 to hDoc.All.length - 1
  MsgBox hDoc.All(i).tagName & ": OuterHTML: " & hDoc.All(i).outerHTML
Next i

This will show you the tagNameand actual HTML for each element on the page (LIVE).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文