你好,我有一个网站从 alexa bat 获取数据,因为两三天后它没有返回任何东西我不知道 alexa 是否改变了某些东西或......
我已经练习了一些代码,所以我请alexa专家指导我
我希望任何人有一些帮助
<?
$url='toolspot.org';
$xml = simplexml_load_file('http://data.alexa.com/data?cli=10&dat=snbamz&url='.$url);
$rank=isset($xml->SD[1]->POPULARITY)?$xml->SD[1]->POPULARITY->attributes()->TEXT:0;
$web=(string)$xml->SD[0]->attributes()->HOST;
echo $web." has Alexa Rank ".$rank;
?>
第二个代码
<?php
class Get_Alexa_Ranking{
/**
* Get the rank from alexa for the given domain
*
* @param $domain
* The domain to search on
*/
public function get_rank($domain){
$url = "http://data.alexa.com/data?cli=10&dat=snbamz&url=".$domain;
//Initialize the Curl
$ch = curl_init();
//Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,2);
//Set the URL
curl_setopt($ch, CURLOPT_URL, $url);
//Execute the fetch
$data = curl_exec($ch);
//Close the connection
curl_close($ch);
$xml = new SimpleXMLElement($data);
//Get popularity node
$popularity = $xml->xpath("//POPULARITY");
//Get the Rank attribute
$rank = (string)$popularity[0]['TEXT'];
return $rank;
}
}
?>
//Include alexa ranking class
require_once 'get_alexa_ranking.php';
//Create a new object
$alexa = new Get_Alexa_Ranking();
//Get the rank for the domain paulund.co.uk
echo "Rank ".$alexa->get_rank("elhawd.com");