Sunday, 15 September 2013

How to fetch specific number of lines from webpage using cURL using C

How to fetch specific number of lines from webpage using cURL using C

I am a newbie in cURL and trying to implement some application, which
could allow user to fetch specific data from an HTML page (dynamic) and
save it to .txt
Application is c/c++ based and so far i am able to fetch the whole contant
of HTML page.
This is the code i am refering:-
#include "stdafx.h"
#pragma comment(lib, "curllib_static.lib")
#include "curl/curl.h"
#pragma comment(lib, "wldap32.lib")
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "ssleay32.lib")
#pragma comment(lib, "openldap.lib")
#pragma comment(lib, "libeay32.lib")
void get_page(const char* url, const char* file_name)
{
CURL* easyhandle = curl_easy_init();
// time = 100;
curl_easy_setopt( easyhandle, CURLOPT_URL, url ) ;
curl_easy_setopt (easyhandle, CURLOPT_CONNECTTIMEOUT, .29);
FILE* file = fopen( "my.txt", "a+");
curl_easy_setopt( easyhandle, CURLOPT_WRITEDATA, file) ;
// curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_easy_perform( easyhandle );
curl_easy_cleanup( easyhandle );
fclose(file);
}
int main()
{
get_page( "http:couldbeanything.com", "style.css" ) ;
return 0;
}
So, this code fetches whole page and i just want to fetch some specific
number of lines using it (for example - 5)
I searched and came across something called "PHP dom parser" and is there
some way to implement this fetching in C/C++ ??
Thanks in advance

No comments:

Post a Comment