Page 1 of 1

Curl grab HTML content

Posted: Thu Dec 10, 2009 7:00 am
by qinglau
Hello Guys,

I need helps in here. I got a webpage which requires login. I use curl to build the http authentication request. It works, but i am not able to grab all the content from my links. I miss all the images. Any tips, i can grab all the images as well.

Regards,
Qing

Code: Select all

<?php
 
// create cURL resource
$URL = "http://10.123.22.38/nagios/nagvis/nagvis/index.php?map=Nagvis_CC";
//Initl curl
$ch = curl_init();
 
//Set HTTP authentication option
curl_setopt($ch, CURLOPT_URL, $URL);  // Load in the destination URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); //Normal HTTP request, not SSL
curl_setopt($ch, CURLOPT_USERPWD, "guest:test" ); // Pass the user name and password
 
// grab URL and pass it to the browser
$content = curl_exec($ch);
 
$result = curl_getinfo($ch);
// close cURL resource, and free up system resources
curl_close($ch);
 
echo $content;
echo $result;
 
?>
 

Re: Curl grab HTML content

Posted: Thu Dec 10, 2009 8:22 am
by qinglau
i add the curl_error to check the information.

I have this message Warning: curl_error(): 2 is not a valid cURL handle resource in C:\xampp\htdocs\LiveServices\LoginTest.php on line 24

Re: Curl grab HTML content

Posted: Thu Dec 10, 2009 5:36 pm
by AbraCadaver
To do this you would have to build your own browser of sorts in PHP using curl. Once you get the HTML you would need to parse it for image links, stylesheet links, js links, etc... and then use curl to fetch those.

I would recommend installing wget and exec() it from PHP.

Re: Curl grab HTML content

Posted: Fri Dec 11, 2009 7:46 am
by qinglau
Hi,

Thanks, I do not know how to do that? Do you have similar example? thanks

Re: Curl grab HTML content

Posted: Fri Dec 11, 2009 10:23 am
by AbraCadaver