使用 C++ 获取网站缩略图快照
有没有办法使用 C++ CGI 捕获网页图像?我一直在四处寻找,虽然我在从 Perl 到 C# 的所有语言中找到了许多实现,但在 C++ 中还没有找到任何实现。
这个想法是让访问站点的用户能够指定 URL。然后,该脚本会拍摄 URL 网站的图片,然后显示将其加载到我正在构建的 C++ CGI 网站。
任何对此的帮助将不胜感激!
谢谢!
Perl 中的示例: Webthumb
Is there any way to capture an image of a web page using a C++ CGI? I've been searching high and low, and while I've found a number of implementations in everything from Perl to C#, haven't been able to find any implementations in C++.
The idea is for a user visiting a site to be able to specify a URL. The script would then take a picture of the URL's website, and then show load it to the C++ CGI website I am building.
Any help on this would be much appreciated!
Thanks!
Example in Perl:
Webthumb
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要渲染网页才能创建快照。要使用 C++ 呈现页面,您需要包含浏览器引擎。您可以使用 Qt(C++ 工具包)轻松完成此操作。
这取自 Qt 文档,是显示网页所需的全部内容。
视图对象有一个 loadFinished 信号。您可以将一些代码连接到该信号。当页面呈现时,您可以按照此处所述拍摄快照。
归结为:
当您获得屏幕截图时,您可以从 cgi 中返回 stdout 上的字节并完成。
You need to render the webpage in order to create a snapshot. To render the page in C++ you need to include a browser engine. You can do this easily using Qt (a toolkit for c++).
This is taken from the documentation of Qt and is all you need to show a webpage.
The view object has a loadFinished signal. You could connect some code to this signal. When the page is rendered you tak a snapshot as described here.
It boils down to:
When you have got the screenshot you can return the bytes on stdout from your cgi and your done.