Newby: How do I strip HTML tags?

David LeBlanc whisper at oz.net
Fri Jun 7 18:37:35 CEST 2002


First you take them out for a nice dinner, then back to your place... ;-)

David LeBlanc
Seattle, WA USA

> -----Original Message-----
> From: python-list-admin at python.org
> [mailto:python-list-admin at python.org]On Behalf Of netvegetable
> Sent: Friday, June 07, 2002 8:18
> To: python-list at python.org
> Subject: Newby: How do I strip HTML tags?
>
>
>
> I'm mucking around with cgi, and I'm trying to work out a way to
> strip the
> html tags of a string. e.g, I want to convert this...
>
> ><font size = 12><b><big>Really Big String</big></b></font>
>
> to this this ...
>
> >Really Big String
>
> ... and store it as a value.
>
> I worked out a crude, but effective way of doing it (see code
> below), but I
> can't escape the feeling there must be a built in way of doing it
> more. If
> nothing else, I'm sure somebody who knows their regular expressions could
> neaten it up (please?).
>
> def strip_html_tags(it):
> 	left = it[:(len(it)/2)]
> 	right = it[(len(it)/2):]
> 	final = left[left.rfind('>')+1:] + right[:right.find('<')]
> 	return final
>
> --
> netvegetable at excite.com
> --
> http://mail.python.org/mailman/listinfo/python-list






More information about the Python-list mailing list