我想解析一个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。为什么呢?