Kunal Gupta
Kunal Gupta

Reputation: 449

Getting Data from Bitsnoop API

I am using the following piece of code to get tracker data (converted from JSON to PHP) and find the sum total of the number of seeders from the BitSnoop API:

$hash = "98C5C361D0BE5F2A07EA8FA5052E5AA48097E7F6";

if(!function_exists("curl_init")) die("cURL extension is not installed");
$url = "http://bitsnoop.com/api/trackers.php?hash=" . $hash . "&json=1";
echo $url;
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r=curl_exec($ch);
curl_close($ch);

$myarr = json_decode($r,true);
print_r($myarr);

But the script is not able to retrieve ANY data from the URL.

Chrome's view-source is working on the page, but any other way of retrieving the source of the page, either via viewsource.in or i-tools don't seem to retrieve any data from the URL as well.

Could anyone explain why is it so? And please provide an alternative way to accomplish the retrieval. Thanks in advance !

Upvotes: 1

Views: 368

Answers (1)

Alexey
Alexey

Reputation: 3484

You should pretend to be a legit browser:

$hash = "98C5C361D0BE5F2A07EA8FA5052E5AA48097E7F6";

if(!function_exists("curl_init")) die("cURL extension is not installed");
$url = "http://bitsnoop.com/api/trackers.php?hash=" . $hash . "&json=1";

$headers = array(
'Host: bitsnoop.com',
'Connection: keep-alive',
'Cache-Control: max-age=0',
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36',
'Accept-Encoding: deflate,sdch',
'Accept-Language: ru,en-US;q=0.8,en;q=0.6');

echo $url;
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$r=curl_exec($ch);

curl_close($ch);

$myarr = json_decode($r,true);
print_r($myarr);

And also it's a good idea to test curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); , however, I did not look if they use or not HTTP redirect

Upvotes: 2

Related Questions