user1518659
user1518659

Reputation: 2246

get the href attribute from the webpage?

I need the get the href attribute from the following:

<tr>
    <td><h2 class="officers"><a href="/finance/stocks/officerProfile?symbol=ABB.N&officerId=232795" class="link">Roger&nbsp;Agnelli</a></h2></td>
    <td>53</td>
    <td>2002</td>
    <td>Non-Executive Member of the Board of Directors</td>
</tr>

what I am trying here is

$a = $tr->getElementsByTagName('a');

echo $a->getAttribute('href');

unable to get the href value.where i am missing?? what i need here i want the href link to be output and after that parse that href link to the 'officer id'.

Hope I am clear with my question.. Help me..

Upvotes: 1

Views: 111

Answers (1)

Leri
Leri

Reputation: 12535

getAttribute is not a method of DOMNodeList it's method of: DOMElement. So you have to do following:

foreach ($a as $element){
    var_dump($element->getAttribute('href'));
}

instead of echo $a->getAttribute('href');.

Upvotes: 1

Related Questions