Beautiful Soup - Remove a tag while keeping Text

1

I have the following tags:

<p>Projeto N <sup>o</sup> 00.000, DE 00 DE JANEIRO DE 0000.</p>

I would like to remove the tag by keeping the text. I needed it to look like this:

<p>Projeto N o 00.000, DE 00 DE JANEIRO DE 0000.</p>
    
asked by anonymous 28.11.2018 / 16:24

1 answer

2

You can use unwrap () :

from bs4 import BeautifulSoup as bs

soup = bs('<p>Projeto N <sup>o</sup> 00.000, DE 00 DE JANEIRO DE 0000.</p>')

soup.sup.unwrap()     # <sup></sup>
print(soup)           # <p>Projeto N o 00.000, DE 00 DE JANEIRO DE 0000.</p>
    
29.11.2018 / 18:44