I don't think anyone mentioned the re module yet, so here's a simple
solution I've been using:

import re
def strip_tags(content):
    tags = re.compile('<.*?>', re.DOTALL)
    return tags.sub('', content)

Note that if you have content like '5 < <p> 10', the above function will
strip '< <p>'. If you only want to remove the <p> tag, you can use this:

import re
def strip_tags(content):
    return re.sub('<[^<]*?>', '', content)



On Wed, Aug 25, 2010 at 8:33 AM, Brian O'Connor <[email protected]> wrote:

> I used stripogram, which I thought worked pretty well.
>
>
> On Wed, Aug 25, 2010 at 11:27 AM, Matthew Hoopes <[email protected]
> > wrote:
>
>>   On Wed, Aug 25, 2010 at 11:13 AM, Lawrence Oluyede <[email protected]
>> > wrote:
>>
>>> On Wed, Aug 25, 2010 at 5:06 PM, Dobrysmak <[email protected]>
>>> wrote:
>>> > As in the title. How to strip HTML tags in a string in Pylons?
>>>
>>> You can do it using my module
>>> http://www.oluyede.org/files/htmlstripper.py
>>>
>>> import htmlstripper
>>> print htmlstripper.stripHTML("<HTML>ABBBBB</HTML>", 'ascii')
>>> 'ABBBBB'
>>>
>>> HTH
>>>
>>> --
>>> Lawrence Oluyede
>>> [eng] http://oluyede.org - http://twitter.com/lawrenceoluyede
>>> [ita] http://www.neropercaso.it
>>> [flickr] http://www.flickr.com/photos/rhymes
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "pylons-discuss" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected]<pylons-discuss%[email protected]>
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/pylons-discuss?hl=en.
>>>
>>>
>> This might also help (answer uses beautiful soup...)
>>
>> http://stackoverflow.com/questions/753052/strip-html-from-strings-in-python
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "pylons-discuss" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<pylons-discuss%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/pylons-discuss?hl=en.
>>
>
>
>
> --
> Brian O'Connor
>
> --
>  You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<pylons-discuss%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to