Home > Backend Development > Python Tutorial > python remove html tags

python remove html tags

高洛峰
Release: 2016-10-18 10:20:18
Original
1574 people have browsed it

Python removes html tags, written by myself, please correct me if there are any deficiencies:

#! /usr/bin/env python
#coding=utf-8
# blueel 2013-01-19
from HTMLParser import HTMLParser
  
class MLStripper(HTMLParser):
    def __init__(self):
        self.reset()
        self.fed = []
    def handle_data(self, d):
        self.fed.append(d)
    def get_data(self):
        return ''.join(self.fed)
  
def strip_tags(html):
    s = MLStripper()
    s.feed(html)
    return s.get_data()
Copy after login

Call:

html = 'ou X de sem juros'


print strip_tags(html)


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template