Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

递归采集有bug #44

Closed
naruone opened this issue Sep 19, 2018 · 1 comment
Closed

递归采集有bug #44

naruone opened this issue Sep 19, 2018 · 1 comment

Comments

@naruone
Copy link

naruone commented Sep 19, 2018

https://doc.querylist.cc/site/index/doc/49

<?php
require 'QueryList/vendor/autoload.php';
use QL\QueryList;
//获取每个li里面的h3标签内容,和class为item的元素内容
$html =<<<STR
    <div id="demo">
        <ul>
            <li>
              <h3>xxx</h3>
              <div class="list">
                <div class="item">item1</div>
                <div class="item">item2</div>
              </div>
            </li>
             <li>
              <h3>xxx2</h3>
              <div class="list">
                <div class="item">item12</div>
                <div class="item">item22</div>
              </div>
            </li>
        </ul>
    </div>
STR;
$data = QueryList::html($html)->rules(array(
        'title' => array('h3','text'),
        'list' => array('.list','html')
    ))->range('#demo li')->query()->getData(function($item){
        $item['list'] = QueryList::html($item['list'])->rules(array(
                 'item' => array('.item','text')
            ))->query()->getData()->all();
        return $item;
});
print_r($data);
/**
 结果:
 Array
(
    [0] => Array
        (
            [title] => xxx
            [list] => Array
                (
                    [0] => Array
                        (
                            [item] => item1
                        )
                    [1] => Array
                        (
                            [item] => item2
                        )
                )
        )
    [1] => Array
        (
            [title] => xxx2
            [list] => Array
                (
                    [0] => Array
                        (
                            [item] => item12
                        )
                    [1] => Array
                        (
                            [item] => item22
                        )
                )
        )
)
 */

此页上的例子,执行结果 不对,正常结果是这样:

Array
(
    [0] => Array
        (
            [title] => xxx
            [list] => Array
                (
                )

        )

    [1] => Array
        (
            [title] => xxx2
            [list] => Array
                (
                )

        )

)

@naruone
Copy link
Author

naruone commented Sep 19, 2018

找到问题了, 第一次设置的range 在递归里面必须重新设置

@jae-jae jae-jae closed this as completed Sep 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants