from bs4 import BeautifulSoup
html = """
<html><head><title>Example</title><style>body {color: red}</style></head>
<body>
<ul class="list">
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
<script>alert('alarm');</script>
</body>
</html>
"""
soup = BeautifulSoup(html, 'html.parser')
# 1. замена тегов
for ul in soup.find_all('ul'):
ul.name = 'div'
for li in soup.find_all('li'):
li.name = 'span'
# 2. втавка тега
meta = soup.new_tag('meta')
meta.attrs['charset'] = 'utf-8'
soup.find('head').insert_after(meta)
# 3. очистка контента внутри тега
soup.find('script').clear()
# 4. вставка текста
soup.find('head').find('style').append('html {background: black}')
print(soup.prettify())
.flex-container {
height: 300px;
flex-flow: column wrap;
align-content: flex-start;
}