lyxint
2012-01-11 23:03:03 +08:00
用张教主的txt_wrap_by_all
def txt_wrap_by(begin, end, html):
if not html:
return ''
start = html.find(begin)
if start >= 0:
start += len(begin)
end = html.find(end, start)
if end >= 0:
return html[start:end].strip()
def txt_wrap_by_all(begin, end, html):
if not html:
return ''
result = []
from_pos = 0
while True:
start = html.find(begin, from_pos)
if start >= 0:
start += len(begin)
endpos = html.find(end, start)
if endpos >= 0:
result.append(html[start:endpos].strip())
from_pos = endpos+len(end)
continue
break
return result
ps = txt_wrap_by_all('<p>', '</p>', html)