• 2
  • 新人请关照

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(Tightenco\Collect\Support\Collection)[512]
  protected 'items' => 
    array (size=20)
      0 => null
      1 => null
      2 => null
      3 => null
      4 => null
阅读 181
评论
    0 个回答
    撰写回答

    登录后参与交流、获取后续更新提醒

    相似问题
    推荐文章