这是我的密码:
$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并计算这个表达式时,它工作得很好。
发布于 2014-07-25 01:29:29
foreach($result as $node)
{
echo $node->getAttribute('href');
}nodeValue属性用于获取节点的文本值。
getAttribute()方法返回属性值。
https://stackoverflow.com/questions/24944901
复制相似问题