使用正则表达式去掉字符串里的html标签提取中文

import re

htmlString = '<a  href="https://m.weibo.cn/p/index?containerid=100808edb33656f8aaf7c68add26ad8d0fdba4&extparam=%E6%97%A9%E9%A4%90&luicode=10000011&lfid=100103type%3D1%26q%3D%E8%85%8A%E8%82%A0" data-hide=""><span class=\'url-icon\'><img style=\'width: 1rem;height: 1rem\' src=\'http://n.sinaimg.cn/photo/5213b46e/20181127/timeline_card_small_super_default.png\'></span><span class="surl-text">早餐</span></a><br />腊肠蛋炒饭+奇异果?+奶茶☕️<br />这两日又风又雨的,这老天真是说变脸就变脸啊<span class="url-icon"><img alt=[笑cry] src="//h5.sinaimg.cn/m/emoticon/icon/default/d_xiaoku-7430606cb7.png" style="width:1em; height:1em;" /></span>来,喝杯奶茶压压惊<span class="url-icon"><img alt=[馋嘴] src="//h5.sinaimg.cn/m/emoticon/icon/default/d_chanzui-ad3f4f182c.png" style="width:1em; height:1em;" /></span> '

str= re.sub(r'<.*?>','',htmlString)
print(str)

返回结果:
早餐腊肠蛋炒饭+奇异果?+奶茶☕️这两日又风又雨的,这老天真是说变脸就变脸啊来,喝杯奶茶压压惊

上一篇:Python内置对象汇总


下一篇:redis学习笔记-04:redis五大数据结构类型