无需滚动即可捕获网页截图 [英] Capture screenshot of webpage without scrolling

查看:112
本文介绍了无需滚动即可捕获网页截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在没有实际滚动页面的情况下获取网页的屏幕截图。



到目前为止,我已经能够完成以下任务:

Selenium Webdriver:捕获整个网页的屏幕截图而不滚动但不幸的是它适用于IE和Firefox。使用Chrome和Safari,它只捕获屏幕上可见的区域(这些浏览器的已知问题)。

CopyFromScreen和GDI方法:通过滚动捕获整个网页通过它,捕获每个滚动的截图,然后缝合这些截图以获得生成的位图。



我想我可以通过使用WebBrowser Control为IE做这个,但我我正在寻找一个适用于所有浏览器的通用选项,而不是任何浏览器。



它是否可能(可能是任何Windows API或任何其他替代方案我不知道)?



如果重要的是我在C#工作。

Is there any way I can get the Screenshot of a Webpage without actually scrolling through the page.

Till now I have been able to accomplish the following:
Selenium Webdriver: Capture Screenshot of the Entire Webpage without scrolling but unfortunately It works fine with IE and Firefox. With Chrome and Safari , it captures only the area which is visible on the Screen (Known Issue with these Browsers).
CopyFromScreen and GDI methods: Capture the entire Webpage by scrolling through it, capturing the screenshots on every scroll and then stitching those Screenshots to get the resulting Bitmap.

I think I can do this for IE by using WebBrowser Control but I am looking out for an option which is generic for all the Browsers and NOT specific to any Browser.

Is it even possible (Maybe any Windows API or any other Alternative which I am not aware of) ?

In case it's important I am working in C#.

推荐答案

我不认为有一个通用的解决方案。我建议采用一种截然不同的替代方法。太糟糕了我不知道你的目的。



首先,你应该明白截图通常是一件坏事。例如,文本信息丢失(信息熵增加)。此外,如果显示整个页面需要滚动,则在可比较的屏幕上显示图像也需要滚动。所以为什么?再说一遍,我不知道你的目的......

但是你可以下载这个网站。您可以使用 Web抓取的一些技巧:

http:// en。 wikipedia.org/wiki/Web_scraping [ ^ ]。



如需了解更多细节,请查看我过去的答案:

从网页获取特定数据 [ ^ ],

如何从其他站点获取数据 [ ^ ]。



-SA
I don't think there is a universal solution. I would suggest a very different alternative approach. Too bad I don't know your purpose.

First of all, you should understand that the screenshot is generally a bad thing. For example, text information is lost (informational entropy grows). Also, if showing the whole page needs scrolling, the showing of the image on comparable screen also would need scrolling. So why? Again, I don't know your purpose…
But you can download the site. You can use some techniques of Web scraping:
http://en.wikipedia.org/wiki/Web_scraping[^].

For some further detail, please see my past answers:
get specific data from web page[^],
How to get the data from another site[^].

—SA


没有通用解决方案没有Windows API调用为您执行此操作。我唯一一次看到在各种浏览器上运行的GOOD实现的唯一一次是使用了滚动和快照技术。
There is no universal solution and no Windows API call to do this for you. The only time I've ever seen a GOOD implementation of this that worked on various browsers was one that used the scroll-and-snapshot technique.


这篇关于无需滚动即可捕获网页截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆