开发者

Problem with Xpath PHP

Im tring to access some links through Google using xpath. The below does works fine and all the links are shown.

    $query = $xpath->evaluate("/html/body//a");

    for ($x=0 ; $x < $query -> length; $x++)
    {
        $href=$query->item($x);

               $url=$href->getAttribute('href');
        echo $url."<br>";
    }

But when i try the below xpath nothing is shown..Im sure that the xpath is correct coz its evaluated and the result is shown in xpather..

/html/body[@id='gsr']/div[@id='cnt']/div[@开发者_Go百科id='res']/div[1]/ol/li/div//cite
    for ($x=0 ; $x < $query -> length; $x++)
    {
        $href=$query->item($x);

               $url=$href->getAttribute('cite');
        echo $url."<br>";
    }

can some one please tell me what i am doin wrong? any help will be much appreciated


Your XPath expression selects 'cite' elements, then you are calling getAttribute('cite') on those element nodes. I don't think HTML 'cite' elements are supposed to have an attribute of the same name. Maybe instead of calling getAttribute('cite') on the 'cite' element nodes you rather want to access $href->textContent.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜