分享

采集笔记

 七星棺材 2015-12-15
参考网址:http:///article-5.html

在thinkphp3.2中使用QueryList有个简单的方法:
1.在 \ThinkPHP\Library\Org\ 目录下新建一个JAE文件夹。
2.把QueryList以及依赖库复制进去。

![QueryList](http://querylist-uploads.stor.sinaapp.com/answer/20140714/26ae3a5f80f29531d7ab8473c5d531e4.png)

3.在控制器里面 import('Org.JAE.QueryList'); 导入QueryList 就可以了。

**下面是演示代码:**
{{{
<?php
// 本类由系统自动生成,仅供测试用途
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
public function index(){
header("Content-type:text/html;charset=GB2312");
import('Org.JAE.QueryList');

//采集OSC的代码分享列表,标题 链接 作者
$url = "http://www.oschina.net/code/list";
$reg = array("title"=>array(".code_title a:eq(0)","text"),"url"=>array(".code_title a:eq(0)","href"),"author"=>array("img","title"));
$rang = ".code_list li";
//使用curl抓取源码并以GB2312编码格式输出
$hj = \QueryList::Query($url,$reg,$rang,'curl','GB2312');
$arr = $hj->jsonArr;
echo "<pre>";
print_r($arr);
echo "</pre><hr/>";

//如果还想采当前页面右边的 TOP40活跃贡献者 图像,得到JSON数据,可以这样写
$reg = array("portrait"=>array(".hot_top img","src"));
$hj->setQuery($reg);
$json = $hj->getJSON();
echo $json . "<hr/>";

//采OSC内容页内容
$url = "http://www.oschina.net/code/snippet_186288_23816";
$reg = array("title"=>array(".QTitle h1","text"),"con"=>array(".Content","html"));
$hj = \QueryList::Query($url,$reg);
$arr = $hj->jsonArr;
echo "<pre>";
print_r($arr);
echo "</pre><hr/>";

}
}
}}}




    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多