How do I make BeautifulSoup parse the contents of textarea tags as HTML?

Posted by brofield on Stack Overflow See other posts from Stack Overflow or by brofield
Published on 2010-04-19T05:49:58Z Indexed on 2010/04/19 5:53 UTC
Read the original article Hit count: 191

Before 3.0.5, BeautifulSoup used to treat the contents of <textarea> as HTML. It now treats it as text. The document I am parsing has HTML inside the textarea tags, and I am trying to process it.

I've tried:

    for textarea in soup.findAll('textarea'):
        contents = BeautifulSoup.BeautifulSoup(textarea.contents)
        textarea.replaceWith(contents.html(text=True))

But I'm getting errors. I can't find this in the documentation, and the alternative parsers aren't helping. Anyone know how I can parse the textareas as HTML?

© Stack Overflow or respective owner

Related posts about python

Related posts about beautifulsoup