I voted to close it as a duplicate, but if you use it, reusing the slice answer from the top answer on the right will get this solution:
from BeautifulSoup import BeautifulSoup html = ''' <div> <p>dvgbkfbnfd</p> <div> <span>dsvdfvd</span> </div> <p>fvjdfnvjundf</p> </div> ''' soup = BeautifulSoup(html) for match in soup.findAll('div'): match.replaceWithChildren() print soup
... which produces the result:
<p>dvgbkfbnfd</p> <span>dsvdfvd</span> <p>fvjdfnvjundf</p>
source share