0

我正在尝试从 Contrie 接收有关 Alexa 热门站点的信息,并且我希望收到:

  • 网站位置;
  • 网址;

对于我已经获得的 URL,但是当我为网站位置添加标签时,某些东西不起作用,这是我的代码:

<?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>"; 
}
} 


?>

我得到这个:

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



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

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

4 回答 4

6

要使用 PHP 获得网站的 Alexa 排名,您可以使用以下代码:

<?
$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;
?>

希望有帮助

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

于 2013-11-04T11:14:01.007 回答
3

为什么不使用官方API

1,000 个请求的成本为 0.15 美元,而且您将获得 SimpleXML 可读的漂亮 XML。作为奖励 - 您不会违反 alexa 使用条款。

于 2013-11-04T11:13:21.337 回答
1

看看这个...会帮助你..

 http://www.phpclasses.org/package/4873-PHP-Get-site-ranking-information-from-Alexa-site.html
于 2013-11-04T12:05:04.117 回答
0

您可以尝试以下代码:

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

希望对你有帮助

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

于 2014-11-04T10:00:53.493 回答