Replacing Tags With Beautiful Soup
Notes
To replace a tag in Beautful Soup, find the element then call its replace_with method passing in either a string or tag.
from bs4 import BeautifulSoup
soup = BeautifulSoup(html)
element = soup.find(id=tag_id)
element.replace_with("text")
tag = soup.new_tag("b")
tag.string = "be bold"
element.replace_with(tag)