Stripping all the tags from HTML to get pure text

From Media Design: Networked & Lens-Based wiki
Jump to navigation Jump to search

You can use nltk.util.clean_html to remove all tags

import nltk.util
nltk.util.clean_html(source)

example:

nltk.util.clean_html("<html><head><title>Hello</title><script>var foo=3;</script></head><body><p>This is <u>some crazy text</u>. OK!</body></html>")
result:
'Hello This is some crazy text . OK!'