Remove tags within tag using Beautiful Soup

Asked

Viewed 75 times

-1

I need to remove all span tags inside the p tags keeping their content.

Html code:

<p>Conceito <span>e</span> <span>Signi</span>ficado<span> </span>de <span>Tex</span>to.</p>

<p><span>Geralmente</span>, entendemos <span>o</span> texto como um <span>conjunto</span> de frases</p>

Expected result:

<p>Conceito e Significado de Texto.</p>

<p>Geralmente, entendemos o texto como um conjunto de frases.<p>
  • What you tried to do and what you got?

  • I tested a for i in Soup.find_all('p'): and I used a method to remove span tags keeping the text but the result is that it does not change in Soup.

1 answer

1


linha1 = "<p>Conceito <span>e</span> <span>Signi</span>ficado<span> </span>de <span>Tex</span>to.</p>"
linha2 = "<p><span>Geralmente</span>, entendemos <span>o</span> texto como um <span>conjunto</span> de frases</p>"

linha1 = linha1.replace('<span>','').replace('</span>','')
linha2 = linha2.replace('<span>','').replace('</span>','')

print(linha1)
print(linha2)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.