如何获得完全计算的 HTML(而不是源 HTML)?
给定一个使用大量 javascript 生成 HTML 的网页,我怎样才能获得由浏览器解析的最终计算 HTML 而不是源 HTML?换句话说,假设一个页面有很多围绕 javascript 函数的标签,这些函数在被调用时会返回一些 HTML。当我查看页面源代码时,我看到的是脚本函数调用,而不是它生成的 HTML。
如何获取网页生成的所有 HTML?
我注意到 Firebug 似乎能够看到 HTML 而不是脚本,但它似乎没有任何方法来保存整个页面,只能保存其中的一小部分。
更新:
感谢所有的答案。但是,我仍然无法使用这些技术获得在 Firebug 控制台中看到的 HTML。对于我的示例页面,我使用我自己的 Facebook 个人资料的“信息”选项卡。如果您在该页面上查看源代码,您将看到许多标题为“big_pipe.onPageletArrive()”的脚本。但是,如果您在 Firebug 中查看它,您会发现每个函数调用都会呈现为 HTML。我尝试了在 Firebug 中右键单击标签、在 Webdev 工具栏中查看生成的源代码以及 Chrome 建议,但它们都给了我脚本调用,而不是 HTML。
还有其他想法吗?
更新 2:
当我说这些函数中的每一个都在 Firebug 中呈现为 HTML 时,我不太正确。仅当我在页面中选择它们并右键单击 -> 检查元素时,它们才会呈现。然后它似乎将其渲染出来。所以也许我的问题变成了如何让 Firebug 自动渲染出所有 HTML,以便您可以选择并保存它? (或者我愿意接受任何其他解决方案来获取此 HTML)。
Given a webpage that uses lots of javascript to generate its HTML, how can I get the final computed HTML being parsed by the browser instead of the source HTML? In other words, presume a page has lots of tags surrounding javascript functions that, when called, return some HTML. When I view the source of the page, I see the script function call, not the HTML it produces.
How could I get all of the HTML produced by a webpage?
I've noticed that Firebug appears able to see the HTML instead of the scripts, but it doesn't appear to have any way to save the whole page, only little segments of it.
Update:
Thanks for all the answers. However, I'm still not getting the HTML I see in Firebug's console with any of those techniques. For my example page, I'm using the 'Info' tab of my own Facebook profile. If you view source on that page, you'll see lots of scripts with the title 'big_pipe.onPageletArrive()'. However, if you look at it in Firebug, each of those function calls renders out to HTML. I tried the right-click on the tag in Firebug, the View Generated Source in the Webdev Toolbar, and the Chrome suggestion, but they all give me the script call, not the HTML.
Any other ideas?
Update 2:
When I said each of those functions renders out to HTML in Firebug, I wasn't quite correct. They only render out if I select them in the page and right click->Inspect Element. Then it appears to render it out. So maybe my question has become how do you get Firebug to automatically render out all of the HTML so you can select and save it? (Or I'm open to any other solution for grabbing this HTML).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
使用 Firebug 的 HTML 选项卡,您可以右键单击
元素,然后单击“复制 HTML”。
您可以使用 Chrome/Safari 中的开发人员工具执行相同的操作。
With Firebug's HTML tab, you can right click on the
<html>
element, and click "Copy HTML".You can do the same thing with Developer Tools in Chrome/Safari.
Firefox 的Web 开发人员工具栏有一个提供此功能的“查看生成的源代码”选项。
The Web Developer Toolbar for Firefox has a "View Generated Source" option which provides this functionality.
如果您想要一个实时版本,是可点击的,然后简单地省略上面代码中的注释标签。
If you want a live version that is clickable, then simple leave out the comment tags in the above code.
我在使用 Javascript 生成的页面时遇到问题:只有向下滚动页面,内容才会呈现,因此复制的 HTML 不完整。所有基于 Chrome 的建议都发生在我身上。
这个问题是通过以下技巧解决的:
I was having problems with a page generated by Javascript: the content would only render if the page was scrolled down, so the copied HTML was incomplete. This happened to me with all suggestions based on Chrome.
This issue was solved by the following trick:
所以是的,用那个...
so yea, use that...
一般情况下是不可能的。以下是我的书签的摘录,它依赖于非标准
outerHTML
:注意:DTD 丢失并且根本无法检索。
It is not possible generally. Here is excerpt from my bookmarklet which relies on non-standard
outerHTML
:Note: DTD is missing and not retrievable at all.