上路抗压,野爹常来

PHP QueryList采集器

百度下载QueryList类库文件

/**
  * 抓取数据源
  * @param $rules    array    抓取规则
  * @param $url      string   url
  * @return mixed
  */
function getQueryList($rules, $url)
{
    $html = file_get_contents($url);
    $QL = new \QL\QueryList();
    return $QL::Query($html, $rules)->data;
}

//创建QL文件夹,引入phpQuery.php和QueryList.php
//在QueryList.php中添加
use phpQuery,Exception,ReflectionClass;
require "phpQuery.php";

//使用
require_once("./QL/QueryList.php");
$rules = [
    'ztgk' => ['.p1 + span', 'text'],
    'ztgk_a' => ['.p1 + span>small', 'text'],
    'jkzs' => ['.c_main ul>li:eq(4)', 'text'],
    'jkzs_a' => ['.c_main ul>li:eq(4)>label', 'text'],
    'xyys' => ['.c_main ul>li:eq(6)', 'text'],
    'xyys_a' => ['.c_main ul>li:eq(6)>label', 'text'],
    'xysz' => ['.c_main ul>li:eq(7)', 'text'],
    'xysz_a' => ['.c_main ul>li:eq(7)>label', 'text'],
];
$url1 = "http://www.xzw.com/fortune/$url";
$data['jintian'] = $comm->getQueryList($rules, $url1);
posted @ 2021-04-23 10:15  上路抗压  阅读(97)  评论(0编辑  收藏  举报