主页 > 编程资料 > PHP >
发布时间:2014-10-28 作者:网络 阅读:224次

Alexa接口

Alexa的XML API接口是:http://data.alexa.com/data?cli=10&url=%YOUR_URL%

如果想获取更多的数据可以用:http://data.alexa.com/data?cli=10&dat=snbamz&url=%YOUR_URL%

用http://data.alexa.com/data?cli=10&dat=snbamz&url=baidu.com返回的数据如下:

  <?xml version="1.0" encoding="UTF-8"?>
   
  <ALEXA VER="0.9" URL="baidu.com/" HOME="0" AID="5ENjk1UlIcc1fJ" IDN="baidu.com/">
  <RLS PREFIX="http://" more="82">
  <RL HREF="21cn.com/" TITLE="21cn.com"/>
  <RL HREF="163.com/" TITLE="网易"/>
  <RL HREF="taobao.com/" TITLE="淘宝网"/>
  <RL HREF="sohu.com/" TITLE="搜狐首页"/>
  <RL HREF="sina.com.cn/" TITLE="新浪首页"/>
  <RL HREF="qq.com/" TITLE="QQ.COM"/>
  <RL HREF="people.com.cn/" TITLE="人民网"/>
  <RL HREF="www.3721.com/" TITLE="网络实名"/>
  <RL HREF="search.21cn.com/" TITLE="21cn_com - 搜索引擎"/>
  <RL HREF="e.pku.edu.cn/" TITLE="天网中英文搜索"/>
  </RLS>
  <SD TITLE="A" FLAGS="DMOZ" HOST="baidu.com">
  <TITLE TEXT="Baidu.com"/>
  <ADDR STREET="The Ideal International Bldg, 12th floor" CITY="Beijing 100080, " STATE="Beijing" ZIP="" COUNTRY="" />
  <CREATED DATE="11-Oct-1999" DAY="11" MONTH="10" YEAR="1999"/>
  <PHONE NUMBER="+86 1082607100"/>
  <OWNER NAME="2009 Baidu "/>
  <EMAIL ADDR="baidu_dns_master@baidu.com"/>
  <ALEXAPRO TIER="intro"/>
  <LANG LEX="zh-CN"/>
  <LINKSIN NUM="191219"/>
  <SPEED TEXT="1517" PCT="56"/>
  <REVIEWS AVG="4.0" NUM="98"/>
  <CHILD SRATING="0"/>
  </SD>
   
  <KEYWORDS>
  <KEYWORD VAL="Chinese Simplified"/>
  </KEYWORDS><DMOZ>
  <SITE BASE="baidu.com/" TITLE="Baidu.com" DESC="The leading Chinese language search engine, provides &amp;quot;simple and reliable&amp;quot; search experience, strong in Chinese language and multi-media content including MP3 music and movies, the first to offer WAP and PDA-based mobile search in China.">
  <CATS>
  <CAT ID="Top/World/Chinese_Simplified_CN/计算机/互联网络/搜寻/搜索引擎" TITLE="搜寻/搜索引擎" CID="254859"/>
  </CATS>
  </SITE>
  </DMOZ>
  <SD>
  <POPULARITY URL="baidu.com/" TEXT="5" SOURCE="panel"/>
  <REACH RANK="6"/>
  <RANK DELTA="+0"/>
  <COUNTRY CODE="CN" NAME="China" RANK="1"/>
  </SD>
  </ALEXA>


其中POPULARITY元素中的TEXT属性的值5就是Alexa排名。

用PHP实现通过Alexa API 获取Alexa排名的代码为:
<php>
function getAlexaRank ($Domain){
     $line = "";
     $data = "";
     $URL = "http://data.alexa.com/data/?cli=10&dat=snba&url=". $Domain ;
     $fp = fopen ($URL ,"r");
     if ($fp ){
           while (!feof ($fp )){
                $line = fgets ($fp );
                $data .= $line ;
           }
           $p= xml_parser_create ();
           xml_parse_into_struct ($p , $data , $vals );
           xml_parser_free ($p );
           for ($i =0 ;$i <count ($vals );$i ++){
  if ($vals [$i ]["tag"]=="POPULARITY"){
      return  $vals [$i ]["attributes"]["TEXT"];
  }
    }
      }
}
?>

<?php
    echo getAlexaRank("baidu.com");
?>

转:
http://www.jb51.net/article/50979.htm

关键字词: