Micro-Blog Data Cleansing (Python edition) __python

Source: Internet
Author: User

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)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.