For details, please refer to: micro-bo Data Cleaning (Java version)
This article is an introduction to the Python version, and only the Data Cleansing section does not contain operations on Excel, including removing HTML tags and removing URL addresses from the information.
Python's code is much simpler than Java.
#-*-Coding:utf-8-*-' Created on December 10, 2013 @author: DaT dev.tao@gmail.com ' ' Import re def dealhtmltags (HTML) : ' Remove HTML tags ' from htmlparser import Htmlparser Html=html.strip () html=html.strip ("\ n") r Esult=[] Parse=htmlparser () parse.handle_data=result.append parse.feed (HTML) parse.close () Return "". J Oin (Result) def dealurl (text): ' Remove URL address from microblogging information ' return re.sub (' http[s]?:/ /(?: [a-za-z]| [0-9]| [$-_@.&+]| [!*\(\),]| (?:%[0-9a-fa-f][0-9a-fa-f]) + ', ', ', text ' if __name__== "__main__": HTML = "" "Next year, I would like to <span style=" color:red "> HP </SPAN> Electricity The brain sees more humanization, each science and technology of thing, more can enhance the thing that the visual enjoys. Address: <a title=http://t.cn/8kuax2z href= "http://t.cn/8kUAX2z target=_blank suda-data=" key=tblog_search_v4.1& Value=weibo_feed_url ": 3651215114310513>http://t.cn/8kuax2z<span class=feedico_active></span>< /a> "" "HTML = dealhtmltags (HTML) print Dealurl (HTML)