Reg strip_tags function in Python.

P

praba kar

Dear All,

In Php I can use strip_tags() function to strip out
all html tags. I want to know that strip_tags()
equivalent function in Python.

regards
praba

________________________________________________________________________
Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony
 
D

Dave Benjamin

praba said:
In Php I can use strip_tags() function to strip out
all html tags. I want to know that strip_tags()
equivalent function in Python.

Here's a simple function based on Python's HTMLParser class. If you need
to reject only certain tags, you'll probably want to subclass
HTMLParser, but for simply stripping all tags, this works:

from HTMLParser import HTMLParser
def strip_tags(html):
result = []
parser = HTMLParser()
parser.handle_data = result.append
parser.feed(html)
parser.close()
return ''.join(result)

See the docs for more details on HTMLParser:
http://docs.python.org/lib/module-HTMLParser.html

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top