xt3mp0r~ Posted November 9, 2009 Share Posted November 9, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/180909-fetching-html-of-a-online-web-page/ Share on other sites More sharing options...
keldorn Posted November 9, 2009 Share Posted November 9, 2009 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; Quote Link to comment https://forums.phpfreaks.com/topic/180909-fetching-html-of-a-online-web-page/#findComment-954411 Share on other sites More sharing options...
xt3mp0r~ Posted November 9, 2009 Author Share Posted November 9, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/180909-fetching-html-of-a-online-web-page/#findComment-954418 Share on other sites More sharing options...
keldorn Posted November 9, 2009 Share Posted November 9, 2009 Its work fine on mine, did you change the useragent, "Lol" might not be accepted and they returned maby a blank page or There be something wrong with your curl installation. Quote Link to comment https://forums.phpfreaks.com/topic/180909-fetching-html-of-a-online-web-page/#findComment-954425 Share on other sites More sharing options...
xt3mp0r~ Posted November 10, 2009 Author Share Posted November 10, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/180909-fetching-html-of-a-online-web-page/#findComment-954592 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.