QueryList icon indicating copy to clipboard operation
QueryList copied to clipboard

range 自身元素怎么获取?

Open arnbunchen opened this issue 2 years ago • 1 comments

image

这个列表 我使用了 range 获取列表,便我想获取 这个div本身的 shopid 我该怎么操作?请大神位指定一二。

arnbunchen avatar Aug 09 '21 08:08 arnbunchen

选择器留空,表示自己,例子:

<?php
require 'querylist/vendor/autoload.php';
use QL\QueryList;

$html =<<<STR
<div>
    <a href="http://xxx.com/1.html" alt="link1">
        链接1
        <span>文本1<span>
    </a>
    <a href="http://xxx.com/2.html" alt="link2">
        链接2
        <span>文本2<span>
    </a>
    <a href="http://xxx.com/3.html" alt="link3">
        链接3
        <span>文本3<span>
    </a>    
</div>
STR;

$data = QueryList::html($html)->rules([
    'a_link' => ['','href'],
    'a_text' => ['', 'text','-span'],
    'a_alt' => ['', 'alt'],
    'span' => ['span', 'text']
])->range('a')->queryData();

print_r($data);
/**
 输出结果:
Array
(
    [0] => Array
        (
            [a_link] => http://xxx.com/1.html
            [a_text] => 链接1
            [a_alt] => link1
            [span] => 文本1
        )
    [1] => Array
        (
            [a_link] => http://xxx.com/2.html
            [a_text] => 链接2
            [a_alt] => link2
            [span] => 文本2
        )
    [2] => Array
        (
            [a_link] => http://xxx.com/3.html
            [a_text] => 链接3
            [a_alt] => link3
            [span] => 文本3
        )
)
 **/

更多例子:https://querylist.cc/docs/api/v4/range

jae-jae avatar Nov 26 '21 10:11 jae-jae