我的代码:
$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>
当我求值时,我只得到Log In。
我想得到http://example.com/login
当我使用Python的lxml并计算该表达式时,它工作得很好。
foreach($result as $node)
{
echo $node->getAttribute('href');
}
nodeValue
属性用于获取节点的文本值。
getAttribute()
方法返回属性的值