Created
December 4, 2012 14:29
-
-
Save h2rd/4204482 to your computer and use it in GitHub Desktop.
Strip html, xml and keep only text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| try: | |
| import lxml.html | |
| def striphtml(data): | |
| t = lxml.html.fromstring(data) | |
| return t.text_content() | |
| except: | |
| import re | |
| def striphtml(data): | |
| t = re.compile(r'<.*?>') | |
| return t.sub('', data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment