doumeba0486
doumeba0486
2013-11-04 11:08

用PHP抓取Alexa信息

已采纳

I'm trying to receive information about Alexa Top Sites from a Contrie, and i would like to receive:

  • Website Position;
  • Website URL;

For the URL i'm getting already, but when i add tag for website position something isnt working, here's my code:

<?php

for ($z=0;$z<2;$z++) {
$html=file_get_contents('http://www.alexa.com/topsites/countries;'.$z.'/PT');
preg_match_all(
    '/<div class="count">.*?<\/div>.*?<a href="\/siteinfo\/.*?">(.*?)<\/a>/s',
    $html,
    $array, //array with sites
    PREG_SET_ORDER
);

for ($i=1;$i<count($array);$i++) {
    echo "<pre>"; print_r($array); echo "</pre>"; 
}
} 


?>

I'm getting this:

Array
(
[0] => Array
    (
        [0] => 
1



google.pt
        [1] => google.pt
    )

[1] => Array
    (
        [0] => 
2
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • ds342222222 ds342222222 8年前

    Why not use the official API?

    It costs $0.15 for 1,000 requests, and you''ll get nice XML readble by SimpleXML. As bonus - you won't violate the alexa terms of usage.

    点赞 评论 复制链接分享
  • doujun7161 doujun7161 7年前

    You can try following code:

    function getAlexaRank($domain) {
            $request = "http://data.alexa.com/data?cli=10&dat=s&url=" . $domain;
            $data = getPageData($request);
            preg_match("/<POPULARITY URL="(.*?)" TEXT="([\d]+)"/si", $data, $p);
            $value = ($p[2]) ? number_format($p[2]) : "n/a";
            $string = "<a href=\"http://www.alexa.com/siteinfo/" . $domain . "\">" . $value . "</a>";
            return $string;
    }
    echo 'Rank: '.getAlexaLinks('www.your-domain.com'); // returns Rank: 118

    Hope helps you

    source: http://w3webtools.com/php-code-get-alexa-rank-and-site-linking/

    </div>
    
    点赞 评论 复制链接分享
  • dongyilai4214 dongyilai4214 8年前

    Check this out...will help you..

     http://www.phpclasses.org/package/4873-PHP-Get-site-ranking-information-from-Alexa-site.html
    
    点赞 评论 复制链接分享
  • duanfeng3879 duanfeng3879 8年前

    To get an Alexa rank of a website using PHP you can use the following code:

    <?
    $url="http://theurl.com";
    $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 an alexa rank of: ".$rank;
    ?>
    

    Hope that helps

    source - http://99webtools.com/php-script-to-get-alexa-rank.php

    点赞 评论 复制链接分享

相关推荐