Home > Net >  Strip tags and keep content with Beautifulsoup
Strip tags and keep content with Beautifulsoup

Time:12-29

I thought this question would have been answered 1000 times, but apparently not (or I'm not looking right!). I want to clean up some overloaded HTML content with BeautifulSoup and remove unwanted tags. In some cases (e.g. <span> or <div>), I want to preserve the content of the tag instead of destroying it entirely with decompose.

With LXML, this can be achieved with strip_tag. How do I do that with BS4?

CodePudding user response:

Check out unwrap method. It preserves content.

  • Related