从beautifulsoup提取HTML表单元格文本

问题描述 投票:0回答:1

我要提取“加拿大”,它基于文本“出生地”。如何用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>
python beautifulsoup
1个回答
0
投票
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())
© www.soinside.com 2019 - 2024. All rights reserved.