码迷,mamicode.com
首页 > 编程语言 > 详细

Python清除常见的网页空格格式

时间:2020-04-21 13:23:48      阅读:79      评论:0      收藏:0      [点我收藏+]

标签:strong   att   python   strip   strip()   ret   mil   str   replace   

def clean(string):
pattern = re.compile(r‘<[^>]+>‘, re.S)
string = pattern.sub(‘‘, string)
string = string.replace(‘\n‘, ‘ ‘).replace(‘\r‘, ‘ ‘).replace(‘&nbsp;‘, ‘ ‘).replace(‘\t‘, ‘ ‘).replace(" ",‘‘)
string = string.strip()
return string

Python清除常见的网页空格格式

标签:strong   att   python   strip   strip()   ret   mil   str   replace   

原文地址:https://www.cnblogs.com/yp19970/p/12743741.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!