Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Strip tags and keep content with Beautifulsoup

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Check out unwrap method. It preserves content.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading