博客列表 >querylist采集

querylist采集

小程_武汉_214945
小程_武汉_214945原创
2020年08月10日 15:50:331441浏览
  • 使用composer安装
  1. composer require jaeger/querylist
  • 以采集925.tv为例子

    • 列表页
      在这里插入图片描述
  • 简单用法

  1. <?php
  2. namespace app\index\controller;
  3. use QL\QueryList;
  4. Use think\Controller
  5. Class Index extends Controller{
  6. //采集数据列表页(catid = 1 足球 catid =2 篮球)
  7. public function get_url($url='http://www.925.tv/?catid=2'){
  8. $data = QueryList::get($url);
  9. return $data;
  10. }
  11. //采集二级分类
  12. public function time_and_tow(){
  13. $data = $this->get_url();
  14. //定义规则
  15. $rules = [
  16. 'category_two' => ['span>em','text'],//span标签下的em下的text
  17. ];
  18. //设置切片
  19. $range = 'section';
  20. $rt = $data->rules($rules)->range($range)->query()->getData();
  21. //处理结果集
  22. $arr = $rt->all();
  23. // echo '<pre>'.print_r($arr,true).'</pre>';
  24. //注销对象
  25. $data->destruct();
  26. return $arr;
  27. }
  28. //获取A队名称
  29. public function get_name_a(){
  30. $data = $this->get_url();
  31. $zhudui = $data->find('.zhudui p')->texts();
  32. $arr = $zhudui->all();
  33. $data->destruct();
  34. // echo '<pre>'.print_r($arr,true).'</pre>';
  35. return $arr;
  36. }
  37. //获取A队LOGO
  38. public function get_logo_a(){
  39. $data = $this->get_url();
  40. $zhudui_img = $data->find('.zhudui img')->attrs('data-original');
  41. $arr = $zhudui_img->all();
  42. // echo '<pre>'.print_r($arr,true).'</pre>';
  43. $data->destruct();
  44. return $arr;
  45. }
  46. //获取B队名称
  47. public function get_name_b(){
  48. $data = $this->get_url();
  49. $kedui = $data->find('.kedui p')->texts();
  50. $arr = $kedui->all();
  51. $data->destruct();
  52. // echo '<pre>'.print_r($arr,true).'</pre>';
  53. return $arr;
  54. }
  55. //获取B队LOGO
  56. public function get_logo_b(){
  57. $data = $this->get_url();
  58. $kedui_img = $data->find('.zhudui img')->attrs('data-original');
  59. $arr = $kedui_img->all();
  60. $data->destruct();
  61. // echo '<pre>'.print_r($arr,true).'</pre>';
  62. return $arr;
  63. }
  64. //循环需要注意释放对象资源
  65. //获取AID
  66. public function aid($urls){
  67. foreach ($urls as $url) {
  68. $ql = QueryList::rules([
  69. //....
  70. 'aid' => ['.biaoti','data-aid']
  71. ]);
  72. $res = $ql->get($url)->query()->getData();
  73. // 释放资源,销毁内存占用
  74. $aid = $res->all();
  75. $s[] = $aid['aid'];
  76. $ql->destruct();
  77. }
  78. return $s;
  79. }
  80. //获取直播地址
  81. public function zhibo_url(){
  82. $data = $this->get_url();
  83. $zhibo_url = $data->find('.index-div a')->attrs('href');
  84. $arr = $zhibo_url->all();
  85. // echo '<pre>'.print_r($arr,true).'</pre>';
  86. $data->destruct();
  87. return $arr;
  88. }
  89. //获取最后一层的IFRAME
  90. public function load_1917($urls){
  91. $rules = [
  92. 'add' => ['.singldl dd:eq(0)','data-add'],
  93. 'tt' => ['.singldl dd:eq(0)','data-tt'],
  94. 'key' => ['.singldl dd:eq(0)','data-key'],
  95. 'cat' => ['.singldl dd:eq(0)','data-cat']
  96. ];
  97. foreach ($urls as $key => $url){
  98. $ql = QueryList::rules($rules);
  99. $r = $ql->get($url)->query()->getData();
  100. $res = $r->all();
  101. $ql->destruct();
  102. //拼接参数
  103. if($res['add'] != ''){
  104. $result[] = 'http://loading.1917.tv/video.php?add='.$res['add'].'&tt='.$res['tt'].'&key='.$res['key'].'&cat='.$res['cat'];
  105. }else{
  106. $result[] = '';
  107. }
  108. }
  109. return $result;
  110. }
  111. //获取直播源
  112. public function vd_src($urls){
  113. $src = [];
  114. $rules = [
  115. 'video_src' => ['#a1','data-key']
  116. ];
  117. foreach ($urls as $key => $url){
  118. if($url != ''){
  119. $ql = QueryList::rules($rules);
  120. $res = $ql->get($url)->query()->getData();
  121. $r = $res->all();
  122. $ql->destruct();
  123. $hexCharCodeStr = trim($r['video_src'],'');
  124. $rawStr = strtolower(substr($hexCharCodeStr,0,2)) === '0x' ? substr($hexCharCodeStr,2) : $hexCharCodeStr;
  125. $len = strlen($rawStr);
  126. $resultStr = [];
  127. if($len % 2 !== 0) {
  128. $src [] = '';
  129. }else{
  130. for ($i=0;$i<$len;$i=$i+2){
  131. $curCharCode = intval(substr($rawStr,$i,2),16);
  132. array_push($resultStr,chr($curCharCode));
  133. }
  134. // return $res = join('',$resultStr);
  135. $src [] = join('',$resultStr);
  136. }
  137. }else{
  138. $src[] = '';
  139. }
  140. }
  141. return $src;
  142. }
  143. }
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议