setQuery() resets the selector


setQuery() method

Return value:QueryList object

Reset the selector, The source code of the target page will not be fetched repeatedly, which is used to repeatedly collect content from multiple places on the same page.

Prototype:

setQuery(array $rules, $range = '',$outputEncoding = null, $inputEncoding = null,$removeHead = false)

Parameter explanation is the same as Query


Usage

<?php
require 'vendor/autoload.php';
use QL\QueryList;
$html =<<<STR
<div class="xx">
    <span>
        xxxxxxxx
    </span>
    <img src="/path/to/1.jpg" alt="">
</div>
STR;
//采集文本
$ql = QueryList::Query($html,array(
        'txt' => array('span:eq(0)','text')
    ));
print_r($ql->data);
//采集图片
$ql->setQuery(array(
        'image' => array('.xx img','src') 
    ));
print_r($ql->data);
/**
采集结果:
Array
(
    [0] => Array
        (
            [txt] => xxxxxxxx
        )
)
Array
(
    [0] => Array
        (
            [image] => /path/to/1.jpg
        )
)
**/