python去掉html标签

python去掉html标签,第1张

s = '<SPAN style="FONT-SIZE: 9pt">开始1~3<SPAN lang=EN-US><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></SPAN>'

import re

d = re.sub('<[^>]+>','',s)

print d

开始1~3

import re

test='<p class="pictext" align="center">陈细妹</p>'

test=re.sub(r'(<[^>\s]+)\s[^>]+?(>)', r'\1\2', test)

print(test)

试试这个:

with open('aa.html') as f:

    s=f.read()

import re

s1=re.sub('<.+?>',' ',s)

with open('bb.html') as wf:

    wf.write(s1)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/7274345.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-03
下一篇 2023-04-03

发表评论

登录后才能评论

评论列表(0条)

保存