与此处.renderContents
类似,我想按该值进行搜索:Beautiful Soup [Python] and the extracting of text in a table
示例HTML:
<table>
<tr>
<td>
This is garbage
</td>
<td>
<td class="thead" style="font-weight:normal">
<!-- status icon and date -->
<a name="post1"><img class="inlineimg" src="img.gif" alt="Old" border="0" title="Old"></a>
19-11-2010, 04:25 PM
<!-- / status icon and date -->
</td>
<td>
This is garbage
</td>
</tr>
</table>
我尝试了什么:
soup.find_all("td", text = re.compile('(AM|PM)'))[0].get_text().strip()
但是,text
的{{1}}参数似乎不适用于此应用:find_all
我需要做什么?
答案 0 :(得分:1)
根本不要指定标记名称,让它找到所需的文本节点。适合我:
soup.find(text=re.compile('(AM|PM)')).strip()