嗨,我对Python和Beautiful soup都是新手。我试图仅从表格的特定部分获取文本。但是似乎findAll的结果不是可以再次运行findAll的BeautifulSoup类型。
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)最后一行错误,带有一个TypeError。我似乎能够对查找结果运行findAll,但不能对后续结果运行findAll。是不是因为我需要做这个元素方面的工作?
作为参考,在最后一行之前,组织的内容看起来像这样,我试图提取文本,比如“肾上腺”:
<td valign="top" height="15" class="tissue1" nowrap> <a class="tissue_link" href="normal_unit.php?antibody_id=20769&mainannotation_id=2065466">Adrenal gland</a> </td>
发布于 2010-10-15 00:19:55
是的,你需要按元素来做。find返回单个元素。findAll返回一个列表,即使该列表只包含一项。
https://stackoverflow.com/questions/3935224
复制相似问题