2013-04-08 143 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方法表。