我要提取“加拿大”,它基于文本“出生地”。如何用beautifulsoup
完成?
<html>
<table class="table1">
<tbody>
<tr>
<td>Date(s) of Birth Used</td>
<td>May 14, 1942</td>
</tr>
<tr>
<td>Place of Birth</td>
<td>Canada</td>
</tr>
</tbody>
</table>
</html>
from bs4 import BeautifulSoup
html = """
<html>
<table class="table1">
<tbody>
<tr>
<td>Date(s) of Birth Used</td>
<td>May 14, 1942</td>
</tr>
<tr>
<td>Place of Birth</td>
<td>Canada</td>
</tr>
</tbody>
</table>
</html>"""
soup = BeautifulSoup(html, 'html.parser')
for row in soup.findAll("td")[3:]:
print(row.get_text())