使用C ++将网页保存到磁盘 [英] Saving a webpage to disk using C++

查看:177
本文介绍了使用C ++将网页保存到磁盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设法在 wininet 库的帮助下从互联网下载了文件但我似乎无法保存网页,也就是以后可以使用文本编辑器或 ifstream

I've managed to download a "file" from the internet with the help of wininet library, but I can't seem to save a "webpage" i.e. something I can edit later on with a text editor or with ifstream.

在这种情况下,我应该使用什么工具?可以 wininet 将网页保存到磁盘吗?我应该考虑 cURL (虽然由于缺少 的文档,我无法下载常规文件, cURL )?我需要学习所谓的套接字编程 吗?

In this case, what are the tools I should resort to? Can wininet save a webpage to disk? Should I consider cURL (though I haven't managed to download regular files due to lack of documentation of cURL)? Do I need to learn what's called socket programming?

注意:我在Windows上使用 > MinGW ,但可以切换到 MSVC (如有必要),我在网页中查找源代码,最终我在网页中的文字之后。
此外,我不熟悉 wininet curl code> 或套接字。我需要学习这些吗?

NB: I'm on Windows, using MinGW but can switch to MSVC if necessary, I'm looking for source code in the webpage, eventually I'm after the text in a webpage. Also, I am not familiar with any of the functions in wininet, curl, or sockets. What do I need to learn of these?

任何帮助都非常感谢!

Any help is greatly appreciated!

推荐答案

如果您的程序要在Windows unix上运行,请使用cURL。否则,请坚持使用MSVC和WinINet函数 http://msdn.microsoft.com/en-us/library/windows/desktop/aa385473(v=vs.85).aspx 在使您的程序运行所需的努力方面更容易使用和分布式(特别是如果你不是静态链接你的程序对cUrl否则,你需要采取libcurl.dll到处你的程序在Windows上运行)。使用WinINet,你只需要包含一个标题和一个库来使用这些函数。

If your program is going to run both on windows and unix, then use cURL. Otherwise, stick with MSVC and WinINet functions http://msdn.microsoft.com/en-us/library/windows/desktop/aa385473(v=vs.85).aspx It's much easier to use in terms of the efforts required to get your program running and distributed (esp. if you're not linking your program against cUrl statically. Otherwise, you'll need to take libcurl.dll everywhere your program runs on Windows). With WinINet, you simply need to include a header and a library to use the functions.

如果你打算使用WinINet,请参考这段代码: http://www.programmershelp.co.uk/showcode.php?e=57 < a>
除了while循环外,使用相同的代码。

If you're going to use WinINet, refer to this code snippet: http://www.programmershelp.co.uk/showcode.php?e=57 Use the same code except for the while loop. Instead of reading one byte at a time, read them by chunks and write them to the output file handle.

如果你打算使用cURL,请参考这篇文章。 :使用C / C ++中的libcurl下载文件

If you're going to use cURL, refer to this post: Download file using libcurl in C/C++

这篇关于使用C ++将网页保存到磁盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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