tags:

views:

43

answers:

1

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[@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

A: 

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.

Martin Honnen