curl-library
Re: help with novice program
Date: Tue, 10 Aug 2010 20:54:04 +0200
Hi Neil, I'm not a pro at all, but maybe I can give you some advice.
I think the general idea should be to download the sourcecode of the
respective website and then search for your string.
In general their are at least two possibilities:
1. Let your program run curl.exe and tell the program to save the
sourcode of the website to some file, load the code from the textfile
and search for your string.
2. Check out the examples in the documentation about simple HTTP and
read the stuff about write callbacks. In your callback, you can eather
search for the string or save the sourcode to a file first.
By the way: I can't imagine something like a remote search, since you
can't tell an independant webserver to do the searching for you.
Cheers,
Michael
Am 10.08.2010 20:33, schrieb neil sutton:
> Hi, I am trying to write a simple program in C++ that obtains user
> input of a string.
> The curl library is then used to make a connection to a given website
> and then - if possible search for all occurance of the given string.
> My questions are:
>
> 1. Is it essential to transfer a copy of the online resource before
> searching for the expression? Could my program search the online
> resource remotely?
>
> 2. This is the simple code i have written so far:
> #include <string>
> #include <iostream>
> #include <curl/curl.h>
>
> using namespace std;
>
> // simple program to obtain user input of a string, connect to a
> website to search for occurances of
> // the string
>
> int main()
> {
> int end(1);
> while (end != 0)
> {
> // Initialisation of curl
> curl_global_init(CURL_GLOBAL_ALL);
> std::string myword;
>
> cout << "Input a word to search for \n";
> cin >> myword;
> cout << "Searching for occurances of " << myword << endl;
> // insert connection and search code here
> // which website?
> // look for myword
>
> cout << "Do you wish to search again? ENTER 0 to end or 1 to
> search again\n";
> cin >> end;
> if (end == 0)
> return 0;
>
> };
>
> curl_global_cleanup();
> }
>
> Now suppose I wish to search the URL www.bbc.co.uk for all occurances
> of the string myword, how would I actually code this? Im not even sure
> that the code i have written properly invokes curl, though it does
> compile. Any suggestions would be welcome. Once i get this program
> working, i will feel more confident in experimenting further.
>
> Many thanks
> neil
>
>
> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
> Etiquette: http://curl.haxx.se/mail/etiquette.html
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-08-10