Python 使用Beauty soup通过文本内容而不是文本查找元素?
与此处的.renderContents类似,我希望通过该值进行搜索: 示例HTML:Python 使用Beauty soup通过文本内容而不是文本查找元素?,python,beautifulsoup,bs4,Python,Beautifulsoup,Bs4,与此处的.renderContents类似,我希望通过该值进行搜索: 示例HTML: <table> <tr> <td> This is garbage </td> <td> <td class="thead" style="font-weight:normal">
<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>
但是,find_all的文本参数似乎不适用于此应用程序:IndexError:list index超出范围
我需要做什么?根本不指定标记名,让它找到所需的文本节点。为我工作:
soup.find(text=re.compile('(AM|PM)')).strip()
它在python 3.4和BeautifulSoup版本4.4.0中适用于您的示例html。您能提供一个复制您的问题的示例吗。@AnandSKumar在Python 3.5中也适用于我。我将示例更新为更具体的版本。我正在努力获取数据。
soup.find(text=re.compile('(AM|PM)')).strip()