php两种方式解析html,获取指数

function getindexfromquery($key){
        //使用phpquery  计时1.774s
        //
        $starttime = explode(' ',microtime());
        include 'phpQuery/phpQuery.php';

        $keyword=urlencode($key);
        $url='http://index.chinaz.com/?words='.$keyword;
        $ch=curl_init();
        curl_setopt($ch,CURLOPT_URL, $url);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch,CURLOPT_HEADER,0);
        $ret=curl_exec($ch);
        curl_close($ch);

        $html=phpQuery::newDocumentHTML($ret);

        $r0=pq(".fz20:eq(0)")->html();
        $r1=pq(".fz20:eq(1)")->html();
        $r2=pq(".fz20:eq(2)")->html();
        $r3=pq(".fz20:eq(3)")->html();
        $r4=pq(".fz20:eq(4)")->html();

        echo '关键词:',$key,"<br />";
        echo '全网指数:',$r0,"<br />";
        echo '整体指数:',$r1,"<br />";
        echo 'pc指数:',$r2,"<br />";
        echo '移动指数:',$r3,"<br />";
        echo '360指数:',$r4,"<br />";
        unset($html);
        $endtime = explode(' ',microtime());
        $thistime = $endtime[0]+$endtime[1]-($starttime[0]+$starttime[1]);
        $thistime = round($thistime,3);
        echo "本网页执行耗时:".$thistime." 秒。".date('Y-m-d H:i:s',time());
    }

    //
    //
    function getindexfromparsedom($key){
        //使用parsedom  计时1.861s
        //
        //
        //
        $starttime = explode(' ',microtime());
        include 'ParserDom.php';
        //获取指数
        $keyword=urlencode($key);
        $url='http://index.chinaz.com/?words='.$keyword;
        $ch=curl_init();
        curl_setopt($ch,CURLOPT_URL, $url);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch,CURLOPT_HEADER,0);
        $ret=curl_exec($ch);
        curl_close($ch);

        $html=new ParserDom($ret);

        $r0=$html->find(".fz20",0);
        $r1=$html->find(".fz20",1);
        $r2=$html->find(".fz20",2);
        $r3=$html->find(".fz20",3);
        $r4=$html->find(".fz20",4);

        echo '关键词:',$key,"<br />";
        echo '全网指数:',$r0->node->textContent,"<br />";
        echo '整体指数:',$r1->node->textContent,"<br />";
        echo 'pc指数:',$r2->node->textContent,"<br />";
        echo '移动指数:',$r3->node->textContent,"<br />";
        echo '360指数:',$r4->node->textContent,"<br />";
        unset($html);
        $endtime = explode(' ',microtime());
        $thistime = $endtime[0]+$endtime[1]-($starttime[0]+$starttime[1]);
        $thistime = round($thistime,3);
        echo "本网页执行耗时:".$thistime." 秒。".date('Y-m-d H:i:s',time());
    }


打赏

看恩吧
网站不承担任何有关评论的责任
  • 最新评论
  • 总共条评论
取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦