PHP 利用SmartKeyQuery 抓取网页数据

1.首先要确认是否有smartkey 组件

PHP 利用SmartKeyQuery 抓取网页数据

2. 根据id 抓取网页上所需要的内容。

 //$formvars["transferCharset"] = "gb2312"; //编码
    //$formvars["transferMethod"] = "GET";//请求方式
    //$formvars["transferAction"] = "";//请求参数
    //$action = C("JAVA_HOST") . "servlet/TransferServlet"; 访问java 控制器
    $action = "http://cpc.people.com.cn/";
    import("SmartKeyPost");
    $smartKeyPost = new \SmartKeyPost();
    $smartKeyPost->submit($action);//$formvars为提交的数组
    //$smartKeyPost->submit($action, $formvars);//$formvars为提交的数组
    \SmartKeyQuery::newDocumentHTML($smartKeyPost->results, 'utf-8');

    $count=0;
    foreach (pq(".p1_3 li")  as $li){
        $po[$count]['text'] = pq($li)->find('a')->text();
        $po[$count]['href'] = pq($li)->find('a')->attr('href');
        $count++;
    }
   return $po;
}

phpquery 文档