require 'vendor/autoload.php';
use GuzzleHttp\Psr7\Response;
use QL\QueryList;
$urls = [
'https://github.com/trending/go?since=daily',
'https://github.com/trending/html?since=daily',
'https://github.com/trending/java?since=daily'
];
$rules = [
'name' => ['h3>a','text'],
'desc' => ['.py-1','text']
];
$range = '.repo-list>li';
QueryList::rules($rules)
->range($range)
->multiGet($urls)
// 设置并发数为2
->concurrency(2)
// 设置GuzzleHttp的一些其他选项
->withOptions([
'timeout' => 60
])
// 设置HTTP Header
->withHeaders([
'User-Agent' => 'QueryList'
])
// HTTP success回调函数
->success(function (QueryList $ql, Response $response, $index){
$data = $ql->queryData();
print_r($data);
})
// HTTP error回调函数
->error(function (QueryList $ql, $reason, $index){
// ...
})
->send();