一个小程序计算tp捐款墙总金额

浏览:1509 发布日期:2016/12/27 分类:功能实现 关键字: 数据采集,TP捐款墙金额计算
计算tp公布的捐款墙总金额
TP发布发布很久了,也算的上是国内数一数二的框架了。国内用户量很大。TP作为开源项目,基本上靠大家的捐赠。嘿嘿,想不想看看TP公布的捐款墙,一共有多少捐款?下面来看一下吧:<?php
set_time_limit(0);
require_once('phpQuery.php');

function curl($url)
{
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $res = curl_exec($ch);
    curl_close($ch);

    return $res;
}

static $all_money = 0;
for($i=1; $i<=100; $i++){

    $url = "http://www.thinkphp.cn/donate/index/p/{$i}.html";
    $res = curl($url);
    $html = phpQuery::newDocumentHTML($res);

    $money_li = $html[".donate-list li"];
    foreach($money_li as $money){
        $money_str = pq($money)->find('.money')->text();
        $all_money += mb_substr($money_str, 1, strlen($money_str)-1, "utf-8");
    }
}

echo $all_money;
phpQuery 这个类大家自己下载,我用的是单文件版本的。运行一下看结果吧:


不到 4w块.......
评论( 相关
后面还有条评论,点击查看>>