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

时间:2021-08-11
本文章向大家介绍使用正则表达式去掉字符串里的html标签提取中文,主要包括使用正则表达式去掉字符串里的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)

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

原文地址:https://www.cnblogs.com/gqv2009/p/15129512.html