Extracting table contents from html with python and BeautifulSoup

后端 未结 1 1278
自闭症患者
自闭症患者 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
    
>>> td = th.findNext('td') >>> td >>> td.text u'2013-06-13'

0 讨论(0)
提交回复
热议问题
Issued on:2013-06-13