使用 C++ 获取网站缩略图快照

发布于 2024-11-05 11:22:10 字数 290 浏览 4 评论 0原文

有没有办法使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦言归人 2024-11-12 11:22:10

您需要渲染网页才能创建快照。要使用 C++ 呈现页面,您需要包含浏览器引擎。您可以使用 Qt(C++ 工具包)轻松完成此操作。
这取自 Qt 文档,是显示网页所需的全部内容。

QWebView *view = new QWebView(ui->centralWidget);
view->load(QUrl("http://qt.nokia.com/"));
view->show();

视图对象有一个 loadFinished 信号。您可以将一些代码连接到该信号。当页面呈现时,您可以按照此处所述拍摄快照。
归结为:

QPixmap::grabWindow(mainwindow->winId())

当您获得屏幕截图时,您可以从 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.

QWebView *view = new QWebView(ui->centralWidget);
view->load(QUrl("http://qt.nokia.com/"));
view->show();

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:

QPixmap::grabWindow(mainwindow->winId())

When you have got the screenshot you can return the bytes on stdout from your cgi and your done.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文