Python/BeautifulSoup - how to remove all tags from an element?

Daniele B picture Daniele B · Apr 25, 2013 · Viewed 108.7k times · Source

How can I simply strip all tags from an element I find in BeautifulSoup?

Answer

shawnl picture shawnl · Jan 27, 2015

With BeautifulStoneSoup gone in bs4, it's even simpler in Python3

from bs4 import BeautifulSoup

soup = BeautifulSoup(html)
text = soup.get_text()
print(text)