How do I use BeautifulSoup to replace a tag with its contents?
beautifulsoup, python
Solution
I've voted to close as a duplicate, but in case it's of use, reapplying slacy's answer from top related answer on the right gives you 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 output:
<p>dvgbkfbnfd</p>
<span>dsvdfvd</span>
<p>fvjdfnvjundf</p>
Problem
How would I use BeautifulSoup to remove only a tag? The method I found deletes the tag and all other tags and content inside it. I want to remove only the tag and leave everything inside it untouched, e.g. change this: ``` <div> <p>dvgbkfbnfd</p> <div> <span>dsvdfvd</span> </div> <p>fvjdfnvjundf</p> </div> ``` to this: ``` <p>dvgbkfbnfd</p> <span>dsvdfvd</span> <p>fvjdfnvjundf</p> ```