使用 C++ 将网页保存到磁盘
我已成功在 wininet
库的帮助下从互联网下载了一个“文件”,但我似乎无法保存“网页” 即我稍后可以使用文本编辑器或 ifstream
进行编辑的内容。
在这种情况下,我应该求助于哪些工具? wininet
可以将网页保存到磁盘吗?我是否应该考虑 cURL
(尽管由于缺乏 cURL
文档,我还没有成功下载常规文件)?我需要学习什么是套接字编程吗?
注意:我在Windows上,使用MinGW,但如果需要的话可以切换到MSVC,我正在网页中寻找源代码,最终我在<网页中的文本。 另外,我不熟悉 wininet
、curl
或套接字中的任何函数。我需要学习这些什么?
非常感谢任何帮助!
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
.
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?
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的程序要在 Windows 和 Unix 上运行,则使用 cURL。否则,请坚持使用 MSVC 和 WinINet 函数 http://msdn.microsoft.com/en-us/library/windows/desktop/aa385473(v=vs.85).aspx 就获得所需的努力而言,使用起来要容易得多您的程序正在运行和分发(尤其是如果您没有将程序静态链接到 cUrl。否则,您需要在 Windows 上运行程序的任何地方使用 libcurl.dll)。使用 WinINet,您只需包含标头和库即可使用这些函数。
如果您要使用 WinINet,请参阅以下代码片段: http:// /www.programmershelp.co.uk/showcode.php?e=57
除了 while 循环之外,使用相同的代码。不要一次读取一个字节,而是按块读取它们并将它们写入输出文件句柄。
如果您要使用 cURL,请参阅这篇文章:在 C 中使用 libcurl 下载文件/C++
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.
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.
If you're going to use cURL, refer to this post: Download file using libcurl in C/C++