1

I am not able to get the contents from the link http://raindrops.in/ainvvy/view/527a727a4251df44558b4567

I tried file_get_contents and curl given in the post How do I get the HTML code of a web page in PHP?

Please help me to get the content of the link. I want to save it into a variable.

Community
  • 1
  • 1
Rohit Singhal
  • 429
  • 1
  • 3
  • 17
  • 4
    can you show here what codes you already tried? And what are the errors encountered? – rccoros Jan 07 '14 at 08:53
  • what did u get when you tried file_get_contents? and please show how you did it. – Roy M J Jan 07 '14 at 08:53
  • It may be that there is a test of referrer that will block your script from retrieving the contents – mplungjan Jan 07 '14 at 08:59
  • Its showing 403 forbidden error. This should help you : http://stackoverflow.com/questions/11680709/file-get-contents-give-me-403-forbidden – Roy M J Jan 07 '14 at 09:04
  • I didn't get any errors but its not working and giving only the top bar of the page. Remaining contents are not coming. – Rohit Singhal Jan 07 '14 at 09:48

3 Answers3

1

Following code is working for me.

echo @file_get_contents('http://raindrops.in/ainvvy/view/527a727a4251df44558b4567');  

make sure you have allow_url_fopen = On in your php.ini file

  • allow_url_fopen is already ON but still it is giving the same problem for me. I got only the first content of the first page which is the top bar – Rohit Singhal Jan 07 '14 at 09:45
1

If you don't have allow_url_fopen = on in you php.ini file, you can use "cUrl" to fetch the remote page. cUrl Manual Page

David Ansermot
  • 6,052
  • 8
  • 47
  • 82
  • 1
    Its already ON..and I have tried by using the curl also but its not working..please help me out – Rohit Singhal Jan 07 '14 at 09:47
  • What's the code you're using to fetch the page with cUrl ? Did you turned cUrl on in your server ? – David Ansermot Jan 07 '14 at 09:48
  • $url ="http://raindrops.in/ainvvy/view/527a727a4251df44558b4567? print=true"; $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); $contents = curl_exec($ch); if (curl_errno($ch)) { echo curl_error($ch); echo "\n
    "; $contents = ''; } else { curl_close($ch); } if (!is_string($contents) || !strlen($contents)) { echo "Failed to get contents."; $contents = ''; } echo $contents;
    – Rohit Singhal Jan 07 '14 at 09:51
1

well, this website relies heavily on AJAX for its content, so getting just the source code (what you are doing with cUrl or file_get_contents will only give you an empty page.

You have 2 choices to get the "real" content (the player presentation) :

  • understand the format and logic of those Ajax call and implement them. The AJAX call in your exemple can be done with cUrl

curl 'http://raindrops.in/rest/ainvvy/527a727a4251df44558b4567' -H 'Cookie: __utma=161727679.1871000365.1388669242.1388669242.1390391663.2; __utmb=161727679.3.10.1390391663; __utmc=161727679; __utmz=161727679.1390391663.2.2.utmcsr=stackoverflow.com|utmccn=(referral)|utmcmd=referral|utmcct=/questions/20967366/not-able-to-get-the-contents-of-the-url' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'Accept-Language: en-US,en;q=0.8,fr-FR;q=0.6,fr;q=0.4' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.77 Safari/537.36' -H 'Accept: application/json, text/javascript, /; q=0.01' -H 'Referer: http://raindrops.in/ainvvy/view/527a727a4251df44558b4567' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' --compressed)

  • or use a browser to actually interpret javascript and make the AJAX call. For this option, you can use Phantomjs http://phantomjs.org/ which is great to implement automation of browser behavior (this is a browser, a webkit implementation, that you can script in javascript).
Pixou
  • 1,719
  • 13
  • 23