Curl grab HTML content

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
qinglau
Forum Newbie
Posts: 5
Joined: Tue Dec 08, 2009 9:22 am

Curl grab HTML content

Post 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;
 
?>
 
qinglau
Forum Newbie
Posts: 5
Joined: Tue Dec 08, 2009 9:22 am

Re: Curl grab HTML content

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Curl grab HTML content

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
qinglau
Forum Newbie
Posts: 5
Joined: Tue Dec 08, 2009 9:22 am

Re: Curl grab HTML content

Post by qinglau »

Hi,

Thanks, I do not know how to do that? Do you have similar example? thanks
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Curl grab HTML content

Post by AbraCadaver »

mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply