获取动态渲染网页的 DOM
是否可以通过编程方式获取动态渲染网页的结果 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,如果您获得对
MSHTML.IHTMLDocument2
的引用,例如将 hDoc 声明为这样,您将获得智能感知来帮助您循环遍历该文档中的项目和元素。请记住,引用是实时的,这意味着,通过任何方式(JavaScript)对document
对象(页面)所做的任何更改,或者您对页面引用所做的更改,都将更新并显示在页面,您将能够通过访问所需的元素来查询和检索新值。当然,当您从那里访问链接时,下一页的 DOM 将是 LIVE DOM。如果您有任何具体问题,请告诉我,我会帮助您。我希望我也正确理解了你的问题。
示例:
这将向您显示页面上每个元素的
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 thedocument
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:
This will show you the
tagName
and actual HTML for each element on the page (LIVE).