当我想解析一个HTML页面时,为什么xpath查询返回null?

时间:2018-03-14 07:04:21

标签: xpath

我想解析一个HTML页面,它有一个下一页按钮。按钮标题是tt。我想获得下一页编号的按钮ID。我的代码是:

$dom = new \DOMDocument;

@$dom->loadHTML($response);

$xpath = new \DOMXpath($dom);

$ne = $xpath->query('//a[@class="btn chang-page" and @title="tt"]/@id');

   while ($ne->length > 0) 

        {

        // go to next page and parse nodes in it.
        // $response=nextpage();

         $dom = new \DOMDocument;

         @$dom->loadHTML($response);

         $xpath = new \DOMXpath($dom);

         $ne = $xpath->query('//a[@class="btn chang-page" and @title="tt"]/@id');

    }

此代码适用于第一页和第二页。对于第3页,返回null。为什么呢?

0 个答案:

没有答案