2012-08-27 90 views
1

我需要從以下獲得href屬性:從網頁獲取href屬性?

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

什麼我想這裏是

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

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

無法獲得HREF value.where我失蹤?我需要在這裏我想要輸出href鏈接,然後解析href鏈接到'官員id'。

希望我很清楚我的問題..幫助我..

+0

你會得到什麼? – Leri

+0

未定義的方法DOMNodeList :: getAttribute() – user1518659

回答

1

getAttribute不是DOMNodeList的方法它的方法:DOMElement。所以,你必須做以下幾點:

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

,而不是echo $a->getAttribute('href');