如何在不使用浏览器控件的情况下检测网页的高度
我需要获取在 IE 中渲染时网页的渲染高度。
我目前正在使用 WebBrowser 控件加载 HTML 页面,然后找到文档的 clientHeight(或scrollHeight,我忘了是哪个)。这效果很好。
问题是,由于 API 调用,我需要从 Web 服务运行此代码,并且启动基于 Windows 窗体的控件以在 WebBrowser 控件中加载是丑陋的,并且(我认为)资源匮乏。
那么,是否有一个无头浏览器实现可以让我计算出渲染的 HTML 的可能高度?我知道这不适用于 iframe、滚动的 div 等,并且不需要非常精确(200px 以内就可以了)。
我们测试的 HTML 页面的高度范围从大约 700 像素高到数千像素高,因此计算出粗略高度将是完美的。使用的 HTML 往往非常简单,因为这些页面实际上是 HTML 电子邮件,从电子邮件中提取并发送到 Web 浏览器。
I need to get the rendered height of a web page when rendered in IE.
I'm currently using the WebBrowser control to load an HTML page and then find the document's clientHeight (or scrollHeight, I forget which). This works well.
The problem is, I need this code to run from a web service as a result of an API call and launching a Windows Form based control to load in the WebBrowser control is ugly and (I assume) incredibly resource hungry.
So, is there a headless browser implementation out there that would allow me to figure out the likely height of the rendered HTML? I know this wouldn't work for iframes, divs that scroll etc, and it doesn't need to be super accurate (within 200px would be fine).
The HTML pages we test range from around 700px high to many thousands of pixels high, so figuring out the rough height would be perfect. The HTML used tends to be quite simple, as these pages are actually HTML emails, extracted from the email and sent to a web browser.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这实际上取决于浏览器及其渲染引擎。您可能必须使用渲染器。
如果您的 HTML 是标准 HTML,您应该能够使用 HTMLayout 的内存中渲染功能,并且结果将与其他浏览器类似。
它有一个 .NET 包装器,位于 http://code.google.com/p/nabu-library /
This really depends on the browser and its rendering engine. You will probably have to use a renderer.
If your HTML is a standard one, you should be able to use HTMLayout's in-memory rendering capability and results will be similar to other browsers.
It has a .NET wrapper at http://code.google.com/p/nabu-library/