from bs4 import BeautifulSoup markup = """
This is child of div with id = "parent". Child of "P"
Piyush
""" # parsering string to HTML soup = BeautifulSoup(markup, 'html.parser') # finding tag whose child to be deleted div_bs4 = soup.find('div') print(div_bs4) print('-------') # delete the child element div_bs4.clear() new_tag = soup.new_tag('s', attrs={'sk' : 2, 'level' : 5}) div_bs4.append(new_tag) print(div_bs4)