×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Python
Posted by: Reagan Mitchell
Added: Jun 8, 2015 10:09 PM
Views: 20
Tags: no tags
  1. def stripTags(s):
  2.     ''' Strips HTML tags.
  3.         Taken from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440481
  4.     '''
  5.     intag = [False]
  6.    
  7.     def chk(c):
  8.         if intag[0]:
  9.             intag[0] = (c != '>')
  10.             return False
  11.         elif c == '<':
  12.             intag[0] = True
  13.             return False
  14.         return True
  15.    
  16.     return ''.join(c for c in s if chk(c))