1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#include <curl/curl.h>
#include <iostream>
#include <fstream>
using namespace std;
size_t write_data (void *ptr, size_t size, size_t nmemb, void *stream)
{
return fwrite (ptr, size, nmemb, (FILE*) stream);
}
void GetHTML (string sWebsite, string sTextFile)
{
CURL *curl_handle;
const char *headerfilename = sTextFile.c_str ();
FILE *headerfile;
curl_global_init (CURL_GLOBAL_ALL);
curl_handle = curl_easy_init ();
curl_easy_setopt (curl_handle, CURLOPT_URL, (long) sWebsite.c_str ());
curl_easy_setopt (curl_handle, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt (curl_handle, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt (curl_handle, CURLOPT_WRITEFUNCTION, write_data);
headerfile = fopen (headerfilename,"w");
if (!headerfile)
{
curl_easy_cleanup (curl_handle);
return;
}
curl_easy_setopt (curl_handle, CURLOPT_WRITEDATA, headerfile);
curl_easy_perform (curl_handle);
fclose (headerfile);
curl_easy_cleanup (curl_handle);
ofstream oFile (sTextFile.c_str (), ios_base::app);
oFile << endl << "DONE";
oFile.close ();
}
int main ()
{
GetHTML ("http://google.com", "HTML.txt"); //Get http://google.com's HTML and put it in HTML.txt
ShellExecute (NULL, "open", "HTML.txt", NULL, NULL, SW_SHOW); //Open HTML.txt in Notepad.exe
return 0;
}
|