Jump to content

Fetching HTML of a online web page


xt3mp0r~

Recommended Posts

Hi.

I have been trying to fetch html source of a an online web page.

I tried using file_get_contents() and cURL but i was still unable to fetch the source.

 

Online web page is http://tinyurl.com/yzlzzkk (click on this url, it will take you to the webpage i'm talking about)

 

Following is the cURL code i tried..

file_get_contents() returns nothing too.

 

<?php

$url="http://www.URLOFWEBPAGE.com/PART.html";
$agent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.13) Gecko/2009080315 Ubuntu/9.04 (jaunty) Firefox/3.0.13";

$ch = curl_init();

curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_REFERER, "http://www.URLOFWEBPAGE.com/");
curl_setopt ($ch, CURLOPT_USERAGENT, $agent);

$html=curl_exec ($ch);

curl_close ($ch);

echo $html;

?>

 

Moreover i tried using wget and lynx and was helpless.

I can't fetch html of that particular site, which i want to. Every other site deals perfectly.

 

Any help would be appreciated :)

Link to comment
https://forums.phpfreaks.com/topic/180909-fetching-html-of-a-online-web-page/
Share on other sites

This should work.

 



// Prepare the request
  $url = "set your url here";

    //Set cURL transfer options
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,10);
    
    curl_setopt($ch, CURLOPT_TIMEOUT,10);

    curl_setopt($ch, CURLOPT_USERAGENT,"lol");
    
    curl_setopt($ch, CURLOPT_URL, $url);
    
    curl_setopt($ch, CURLOPT_HEADER, 1);

    
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
    
    // Go !!
    $data = curl_exec($ch);


    //-- Any Curl Error?
    if ( curl_error($ch) ) {
       
        //-- Close cURL handle
        $error = curl_error($ch);
        curl_close($ch);
        //-- All done
        exit($error);
    }

curl_close($ch);

// -- NO error continue?

echo $data;
exit;

Hi keldorn  :)

 

I tried that code, and it doesn't work too.

All i get back is header information

HTTP/1.1 200 OK Date: Mon, 09 Nov 2009 22:43:16 GMT Server: Apache/2 X-Powered-By: PHP/5.2.9 Last-Modified: Mon, 09 Nov 2009 16:48:18 -0500 Vary: Accept-Encoding,User-Agent Content-Length: 0 Content-Type: text/html;charset=UTF-8 

 

Content-length is still 0

no errors.

I tried changing user-agent, but still it returns blank.

The code works perfectly for other sites, just can't fetch source of this particular website.

are you trying to fetch html of that website, which i mentioned in first post ?

 

Also, i highly doubt about my curl installation, as its working perfectly for all other websites..i tried it on 2 different hosting and both give same results.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.