2013-04-08 142 views
2

我閱讀了與我的問題有關的其他線程,但沒有解決問題。BeautifulSoup,'ResultSet'對象沒有屬性'find_all'(已解決)

<h2 class="tabellen_ueberschrift al">Cards</h2> 
<div class="fl" style="width:49%;">  
<table class="tabelle_grafik lh" cellpadding="2" cellspacing="1"> 
     <tr> 
      <th class="al" colspan="3">CA Osasuna</th>    
     </tr> 

      <td class="s10 al"> 
       <a href="/en/sisi/profil/spieler_51713.html" class="fb s10" title="Sisi">Sisi</a> 
       <br /> 
       26. min. 2. yellow card, Time wasting    </td> 
     </tr> 

我想所有的a標籤(會有幾個)表,所以我的代碼中是這樣的:

header = soup.find('h2', text="Cards") 
cards_table = header.find_next_siblings(limit=2) 
for row in cards_table.find_all('a'): 
    print row 

這引起了我

AttributeError: 'ResultSet' object has no attribute 'find_all' 

cards_table是表,我用for循環遍歷它,所以不知道爲什麼這會導致錯誤。想法請?

+1

如果解決了這個問題,那麼關閉你的問題應該發佈你的解決方案作爲答案,並接受它... – 2013-04-08 13:27:16

+0

感謝您的建議。 – nutship 2013-04-08 13:31:42

+0

唯一的障礙是我認爲這個問題可能必須是48小時,儘管...... – 2013-04-08 13:35:25

回答

6

好,代碼缺少一條線:

for line in cards_table: 
    for row in line.find_all('a'): 
     print row 

cards_table是一個列表,所以我們不得不遍歷之前,我們可以使用find_all方法表。