Saving a webpage to disk using C++

戏子无情 提交于 2019-12-18 09:39:25

问题


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!


回答1:


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++



来源:https://stackoverflow.com/questions/7937283/saving-a-webpage-to-disk-using-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!