1
4

2 回答 2

2

尝试

data=[b.string for b in main_div.findAll('b')]
于 2013-03-21T04:08:50.913 回答
2

也许是这样的?

import BeautifulSoup

html = '''<div class="txt"><br> 
\nPower: <b>On</b><br><br>
\nSource: <b>DVI</b><br><br>
\nLamp runtime: <b>396</b> hours<br>
\nLamp remaining: <b>2035</b> hours<br>
\nTotal operation: <b>2551</b> hours<br>
\n</div>'''

soup = BeautifulSoup.BeautifulSoup(html)
bTags = [] 

for i in soup.findAll('b'):
    bTags.append(i.text)

bTags的内容:

[u'On', u'DVI', u'396', u'2035', u'2551']
于 2013-03-21T05:12:23.640 回答