Click to See Complete Forum and Search --> : Read web page and store in string, how? in C


aeav
10-20-2006, 10:54 AM
I need to read a web page and store the result in a string, how can I do that?

I need to store it in a string because I'll search an slice of the string.

I have to use C or C++

thank you all

xrx
10-20-2006, 03:49 PM
Homework, is it?

Piko
10-20-2006, 05:34 PM
What do you need from the website, just one page of HTML code, or do you need it, and all the graphics that are linked threw the HTML.

If you just need the HTML code you could just use a system call to wget, and then fopen the HTML your self, or get clever, and send an XML parser threw it if you need to find some specific information out of it. system("wget <url>"); will download the file to the current work dir. Then you can take the downloaded HTML code, and go running threw it, or load the whole thing into memory, and then delete the file from the disk.


void main()
{
char *page
char *url;
char *command;
strcpy(command, "wget ");
strcat(command, url);
strcat(command, page);

int check = system(command);
if(check != -1)
{
FILE *filePointer(page, "rb");
if(filePointer != NULL)
printf("We got the webpage!\n");

else
printf("The page didn't download!\n");
}

else
printf("The command failed!\n");
}