Smoothing Out a Beautiful Soup Tree
If you edit the HTML tree in Beautiful Soup you should call the smooth method to smooth out any funkiness that got introduced.
from bs4 import BeautifulSoup
soup = BeautifulSoup(html)
for tag_id in tag_ids_to_destroy:
tag = soup.find(id=tag_id)
tag.decompose()
soup.smooth()