zoukankan      html  css  js  c++  java
  • Php获取Alexa排行统计

    在自己的站点上显示Alexa统计信息,除了可以方便自己查看,而且据说还有助于提高alexa排名(因为只要有对这个带链接的统计信息的点击,就如同在浏览器上安装了alexa工具的人浏览了自己的站点一样。只是不知道蜘蛛爬去了是不是也算呢~)

    在站点上显示alexa统计信息,一个很方便的方法就是直接挂上alexa提供的widget。这个widget可以在http://www.alexa.com/siteowners/widgets上面获取。但是挂件并不显示中文排行。作为中文站点,中文排行参数还是很重要的。

    为了自定义显示alexa信息,可以采用php输出。

    主要手段是从http://www.alexa.com/siteinfo/vastars.info页面获取相关数据。比如对vastars.info的描述是这样的:

    Vastars.info has a three-month global Alexa traffic rank of 421,818, and visitors to this site spend roughly 45 seconds on each pageview and a total of two minutes on the site during each visit. Almost all visitors to the site come from China, where it has attained a traffic rank of 26,842. About 3% of visits to Vastars.info are referred by search engines. About 32% of visits to the site are bounces (one pageview only).

    为了获取全球排行,采用了pre_match寻找上面用红色标记的而文字中间的内容。经竹下无为梦提醒,发现并不是所有的站点的描述都和上面一样的格式。所以如果要应用于自己的站点,还要去看看alexa自己站点的描述做相应修改才行。如果alexa经常更新描述格式,这个方法就不太可取了。
    官方挂件的效果




    php代码
    <div>
    <h4 class="widgettitle"><a href="http://www.alexa.com/siteinfo/vastars.info">Alexa统计</a></h4>
    <ul>
    < ?php
    $alexaRankQueryUrl="http://www.alexa.com/siteinfo/vastars.info";
    $strAlexaContent = file_get_contents($alexaRankQueryUrl);
    $patterngr="/global Alexa traffic rank of (.*?), and visitors to this site spend roughly/si";
    $patterncr="/attained a traffic rank of (.*?)\./si";
    $patternsearch="/About (.*?) of visits/si";
    if(preg_match($patterngr,$strAlexaContent,$gr)){
    echo "<li>全球排行:" . $gr[1] . "</li>";
    }
    if(preg_match($patterncr,$strAlexaContent,$cr)){
    echo "<li>中国排行:" . $cr[1] . "</li>";
    }
    if(preg_match($patternsearch,$strAlexaContent,$se)){
    echo "<li>引擎流量:" . $se[1] . "</li>";
    }

    ?>
    </ul>
    </div>

    效果展示

  • 相关阅读:
    python学习笔记3:基础(元组、字符串、列表、字典)
    python学习笔记2:基础(邮件发送)
    pycharm版本控制
    Pycharm版本控制之本地Git用法
    GitHub使用
    qtp简单说明
    查询Activity方便一点的方法
    appium基础框架
    loadrunner基本流程
    python下的unittest框架
  • 原文地址:https://www.cnblogs.com/58top/p/2260350.html
Copyright © 2011-2022 走看看