简体   繁体   English

使用C ++将网页保存到磁盘

[英]Saving a webpage to disk using C++

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" ie something I can edit later on with a text editor or with ifstream . 我已经在wininet库的帮助下设法从互联网上下载了一个“文件” ,但是我似乎无法保存“网页”,即以后可以使用文本编辑器或ifstream编辑的内容。

In this case, what are the tools I should resort to? 在这种情况下,我应该使用哪些工具? Can wininet save a webpage to disk? wininet可以将网页保存到磁盘吗? Should I consider cURL (though I haven't managed to download regular files due to lack of documentation of cURL )? 我应该考虑使用cURL (尽管由于缺少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. 注意:我在Windows上,使用MinGW,但可以在必要时切换到MSVC ,我在网页中寻找源代码,最终我在寻找网页中的文本 Also, I am not familiar with any of the functions in wininet , curl , or sockets. 另外,我对wininetcurl或sockets中的任何功能都不熟悉。 What do I need to learn of these? 我需要了解什么?

Any help is greatly appreciated! 任何帮助是极大的赞赏!

If your program is going to run both on windows and unix, then use cURL. 如果您的程序要同时在Windows Unix上运行,请使用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). 否则,请坚持使用MSVC和WinINet函数http://msdn.microsoft.com/zh-cn/library/windows/desktop/aa385473(v=vs.85).aspx就所需的工作而言,使用起来要容易得多使您的程序运行并分发(特别是如果您不是静态地将程序与cUrl链接在一起的话。否则,您需要在Windows上运行该程序的任何地方都使用libcurl.dll)。 With WinINet, you simply need to include a header and a library to use the functions. 使用WinINet,您只需要包括标题和库即可使用这些功能。

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. 如果要使用WinINet,请参考以下代码段: http : //www.programmershelp.co.uk/showcode.php? e=57使用相同的代码,除了while循环。 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++ 如果要使用cURL,请参阅此文章: 在C / C ++中使用libcurl下载文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM