composer require jaeger/querylist
以采集925.tv为例子
简单用法
<?php
namespace app\index\controller;
use QL\QueryList;
Use think\Controller
Class Index extends Controller{
//采集数据列表页(catid = 1 足球 catid =2 篮球)
public function get_url($url='http://www.925.tv/?catid=2'){
$data = QueryList::get($url);
return $data;
}
//采集二级分类
public function time_and_tow(){
$data = $this->get_url();
//定义规则
$rules = [
'category_two' => ['span>em','text'],//span标签下的em下的text
];
//设置切片
$range = 'section';
$rt = $data->rules($rules)->range($range)->query()->getData();
//处理结果集
$arr = $rt->all();
// echo '<pre>'.print_r($arr,true).'</pre>';
//注销对象
$data->destruct();
return $arr;
}
//获取A队名称
public function get_name_a(){
$data = $this->get_url();
$zhudui = $data->find('.zhudui p')->texts();
$arr = $zhudui->all();
$data->destruct();
// echo '<pre>'.print_r($arr,true).'</pre>';
return $arr;
}
//获取A队LOGO
public function get_logo_a(){
$data = $this->get_url();
$zhudui_img = $data->find('.zhudui img')->attrs('data-original');
$arr = $zhudui_img->all();
// echo '<pre>'.print_r($arr,true).'</pre>';
$data->destruct();
return $arr;
}
//获取B队名称
public function get_name_b(){
$data = $this->get_url();
$kedui = $data->find('.kedui p')->texts();
$arr = $kedui->all();
$data->destruct();
// echo '<pre>'.print_r($arr,true).'</pre>';
return $arr;
}
//获取B队LOGO
public function get_logo_b(){
$data = $this->get_url();
$kedui_img = $data->find('.zhudui img')->attrs('data-original');
$arr = $kedui_img->all();
$data->destruct();
// echo '<pre>'.print_r($arr,true).'</pre>';
return $arr;
}
//循环需要注意释放对象资源
//获取AID
public function aid($urls){
foreach ($urls as $url) {
$ql = QueryList::rules([
//....
'aid' => ['.biaoti','data-aid']
]);
$res = $ql->get($url)->query()->getData();
// 释放资源,销毁内存占用
$aid = $res->all();
$s[] = $aid['aid'];
$ql->destruct();
}
return $s;
}
//获取直播地址
public function zhibo_url(){
$data = $this->get_url();
$zhibo_url = $data->find('.index-div a')->attrs('href');
$arr = $zhibo_url->all();
// echo '<pre>'.print_r($arr,true).'</pre>';
$data->destruct();
return $arr;
}
//获取最后一层的IFRAME
public function load_1917($urls){
$rules = [
'add' => ['.singldl dd:eq(0)','data-add'],
'tt' => ['.singldl dd:eq(0)','data-tt'],
'key' => ['.singldl dd:eq(0)','data-key'],
'cat' => ['.singldl dd:eq(0)','data-cat']
];
foreach ($urls as $key => $url){
$ql = QueryList::rules($rules);
$r = $ql->get($url)->query()->getData();
$res = $r->all();
$ql->destruct();
//拼接参数
if($res['add'] != ''){
$result[] = 'http://loading.1917.tv/video.php?add='.$res['add'].'&tt='.$res['tt'].'&key='.$res['key'].'&cat='.$res['cat'];
}else{
$result[] = '';
}
}
return $result;
}
//获取直播源
public function vd_src($urls){
$src = [];
$rules = [
'video_src' => ['#a1','data-key']
];
foreach ($urls as $key => $url){
if($url != ''){
$ql = QueryList::rules($rules);
$res = $ql->get($url)->query()->getData();
$r = $res->all();
$ql->destruct();
$hexCharCodeStr = trim($r['video_src'],'');
$rawStr = strtolower(substr($hexCharCodeStr,0,2)) === '0x' ? substr($hexCharCodeStr,2) : $hexCharCodeStr;
$len = strlen($rawStr);
$resultStr = [];
if($len % 2 !== 0) {
$src [] = '';
}else{
for ($i=0;$i<$len;$i=$i+2){
$curCharCode = intval(substr($rawStr,$i,2),16);
array_push($resultStr,chr($curCharCode));
}
// return $res = join('',$resultStr);
$src [] = join('',$resultStr);
}
}else{
$src[] = '';
}
}
return $src;
}
}