douwei1944 2013-08-29 16:34
浏览 78
已采纳

Xpath查询辅助嵌套锚点href提取

Here is my code:

$text = '<div class="cgus_post"><a href="?p=15055">Hello</a></div>';
$dom = new DomDocument();
$dom->loadHTML($text);
$classname = 'cgus_post';
$finder = new DomXPath($dom);
$nodes = $finder->query('//div[class="cgus_post"]//@href');

I'm trying to get the href text for an anchor link within the div cgus_post. What's wrong with my query?

  • 写回答

2条回答 默认 最新

  • doubian0284 2013-08-29 16:43
    关注

    probably a missing "@"

    '//div[@class="cgus_post"]//@href'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?