Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
528 views
in Technique[技术] by (71.8m points)

QueryList v4 如何获取html标签自定义属性的值。

<dd class="server-and-time">
    <span class="server-info" data-wordId="123" title="">加载中...</span>
    <p class="time">123212412</p>
</dd>
<dd class="server-and-time">
    <span class="server-info" data-wordId="234" title="">加载中...</span>
    <p class="time">123212412</p>
</dd>
<dd class="server-and-time">
    <span class="server-info" data-wordId="345" title="">加载中...</span>
    <p class="time">123212412</p>
</dd>
<dd class="server-and-time">
    <span class="server-info" data-wordId="567" title="">加载中...</span>
    <p class="time">123212412</p>
</dd>
<dd class="server-and-time">
    <span class="server-info" data-wordId="789" title="">加载中...</span>
    <p class="time">123212412</p>
</dd>

我使用的方法抓取不到data-worldId对应的值

public function index(QueryList $queryList)
{
    $client = new Client();
    $res = $client->request('GET', 'http://www.xxxxxx.com', [
        'headers' => [
            'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36',
            'Accept-Encoding' => 'gzip, deflate, br',
        ]
    ]);

    $html = (string)$res->getBody();
    $currentListRoleZone = $queryList->html($html)->find('.server-info')->attrs('data-wordId');
    var_dump($currentListRoleZone);
}

输出结果

object(TightencoCollectSupportCollection)[512]
  protected 'items' => 
    array (size=20)
      0 => null
      1 => null
      2 => null
      3 => null
      4 => null

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...