views:

23

answers:

1

Hi I'm new to both Python and Beautiful soup. I'm trying to get the text only from a certain part of a table. But it seems the result of a findAll is not a BeautifulSoup type that I can run findAll on again.

select = soup.find('table',{'id':"tp_section_1"})
print "got the right table"
tissues = select.findAll('td',{"class":re.compile("tissue[10]")})
print "got the right cells, now I'd like to get just the text"
tissueText = tissues.findAll(text = True)

The final line errors, with a TypeError. I seem to be able to run findAll on the result of a find but not findAll on the subsequent result. Is it because I need to do this element-wise?

For reference, the contents of tissues, before the final line look like this and I'm trying to extract the text such as "Adrenal gland":

<td valign="top" height="15" class="tissue1" nowrap> <a class="tissue_link" href="normal_unit.php?antibody_id=20769&amp;mainannotation_id=2065466">Adrenal gland</a> </td>

+1  A: 

Yes, you need to do it element-wise. find returns a single element. findAll returns a list, even if the list only contains one item.

Justin Peel