[英]get the URL to the last page of a webpage
$doc = new DOMDocument();
libxml_use_internal_errors(true);
@$doc->loadHTMLFile('http://www.mudah.my/Malaysia/Electronics-3000/directd-for-sale?o=1&q=directd&th=1');
$xpath = new DOMXPath($doc);
$nlist = $xpath->query('//*[@id="list_ads_container"]/div[1]/div[3]/span[1]/a/div');
echo $nlist->item(0)->textContent;
I'm trying to get the URL of the last page of the webpage, but at last what I get is a word "Last" and not the URL. 我正在尝试获取网页最后一页的URL,但是最后我得到的是单词“ Last”而不是URL。
URL is set in href
attribute of <a>
. URL在
<a>
href
属性中设置。 So you don't need to select the last <div>
and get the attribute content like 因此,您无需选择最后一个
<div>
并获得属性内容,例如
$nlist = $xpath->query('//*[@id="list_ads_container"]/div[1]/div[3]/span[1]/a');
$href = $nlist->item(0)->getAttribute('href');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.