[英]xpath cannot get anchor href value
我在從xpath query
獲取anchor href
遇到問題。
這是查詢:
$hrefxpath = $xpath->query('//*[@id="content"]/article[1]/article[1]/div/h2/a[@href]');
foreach($hrefxpath as $item){
var_dump($item->nodeValue);
}
這是HTML:
<div id="content">
<article>
<article>
<div>
<h2>
<a href="hrefvalue">Something Awesome</a>
</h2>
</div>
</article>
</article>
</div>
結果是“ Something Awesome
但是沒有href值。
任何建議將不勝感激。
也就是說,因為您僅輸出nodeValue。 加
var_dump($item->getAttribute('href'));
獲取DOMElement的屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.