3 回答
TA贡献1111条经验 获得超0个赞
使用正则表达式:
import re
ss = '''
<ul class="clearfix">
<li><span class="bold-title">Starts:</span> October 2013</li>"
</ul>
blah blah
<ul class="clearfix">
<li><<a href="/derives/certificats/"> November 2014 </li>"
</ul>
'''
regx = re.compile('<ul +class="clearfix">.+?'
'<li>.*? *([^<>]+?) *</li>',
re.DOTALL)
print regx.findall(ss)
# prints ['October 2013', 'November 2014']
TA贡献1821条经验 获得超4个赞
hold = li.text
for eachTag in li.findAll():
hold = hold.replace(eachTag.text,'')
TA贡献1848条经验 获得超2个赞
使用.contents,它返回一个列表:
>>> from bs4 import BeautifulSoup as BS
>>> html = (stuff above)
>>> soup = BS(html)
>>> print soup.find('li').contents[1].strip()
October 2013
添加回答
举报