Simple function to strip HTML tags from URL

def stripTags(s): ''' Strips HTML tags. ''' intag = [False] def chk(c): if intag[0]: intag[0] = (c != '>') return False elif c == '<': intag[0] = True return False return True return ''.join(c for c in s if chk(c))
When grabbing HTML from the web, you sometimes just want the text, not the HTML tags.

How to run it?
print stripTags('<div style="border:1px solid black;"><p>Hello, <span style="font-weight:bold;">world</span> !</p></div>')

Final result:
Hello, world !

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.