Extracting table contents from html with python and BeautifulSoup

后端 未结 1 1277
自闭症患者
自闭症患者 2020-12-10 14:49

I want to extract certain information out of an html document. E.g. it contains a table (among other tables with other contents) like this:

    
相关标签:
1条回答
  • 2020-12-10 15:25
    >>> from bs4 import BeautifulSoup
    >>> soup = BeautifulSoup(unicodestring_containing_the_entire_htlm_doc)
    >>> table = soup.find('table', {'class': 'details'})
    >>> th = table.find('th', text='Issued on:')
    >>> th
    <th>Issued on:</th>
    >>> td = th.findNext('td')
    >>> td
    <td>2013-06-13</td>
    >>> td.text
    u'2013-06-13'
    
    0 讨论(0)
提交回复
热议问题