By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,695 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,695 IT Pros & Developers. It's quick & easy.

Reg strip_tags function in Python.

P: n/a

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
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
praba kar wrote:
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
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.