Request network operation extension



Request network operation extension

Request extension can carry cookies, forge origins, and forge browsers Wait for any complex network request

Installation:

composer require jaeger/querylist-ext-request

GIT address:

https://github.com/jae-jae/QueryList-Ext-Request.git

Dependencies (please install through Composer Ignore)

Request extension depends on Http class, Git address is: https://github.com/jae-jae/Http.git

Manual installation plug-in tutorial:http://doc.querylist.cc/site/index/doc/7

##Usage 1
$ql = QueryList::run('Request',[
    'http' => [
        'target' => '采集的目标页面',
        'referrer' => '来源地址',
        'method' => '请求方式,GET、POST等',
        'params' => ['提交的参数'=>'参数值','key'=>'value'],
        //等等其它http相关参数,具体可查看Http类源码
    ],
    'callback' => function($html,$args){
        //处理html的回调方法
        return $html;
    },
    'args' => '传给回调函数的参数'
]);
$data = $ql->setQuery(...)->data;

Usage 2

$ql = QueryList::run('Request',[
    'target' => '采集的目标页面',
    'referrer' => '来源地址',
    'method' => '请求方式,GET、POST等',
    'params' => ['提交的参数'=>'参数值','key'=>'value'],
    //等等其它http相关参数,具体可查看Http类源码
]);
$data = $ql->setQuery(...)->data;

The return value is the QueryList object with the html attribute set, and then the setQuery method of QueryList should be called to set the collection rules.


//HTTP操作扩展
$urls = QueryList::run('Request',[
        'target' => 'http://cms.querylist.cc/news/list_2.html',
        'referrer'=>'http://cms.querylist.cc',
        'method' => 'GET',
        'params' => ['var1' => 'testvalue', 'var2' => 'somevalue'],
        'user_agent'=>'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:21.0) Gecko/20100101 Firefox/21.0',
        'cookiePath' => './cookie.txt',
        'timeout' =>'30'
    ])->setQuery(['link' => ['h2>a','href','',function($content){
    //利用回调函数补全相对链接
    $baseUrl = 'http://cms.querylist.cc';
    return $baseUrl.$content;
}]],'.cate_list li')->getData(function($item){
    return $item['link'];
});