[英]PHP - DOMXpath - Get the value
這是我的代碼:
$doc = new DOMDocument;
$doc->loadHTML($source);
$xpath = new DOMXPath($doc);
$result = $xpath->evaluate($xpath);
foreach($result as $node) {
echo $node->nodeValue;
}
//I'm trying to get the href attribute in: <a href="http://example.com/login">Log In</a>
當我評估它時,我只會得到“登錄”。
我想獲取http://example.com/login
當我使用Python的lxml並評估該表達式時,它可以正常工作。
foreach($result as $node)
{
echo $node->getAttribute('href');
}
nodeValue
屬性用於獲取節點的文本值。
getAttribute()
方法返回屬性的值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.