示例
from bs4 import BeautifulSoup
html_content = '''
<div id="content" data="你好">
<p>测试01</p>
<span>测试02</span>
</div>
<div>测试03</div>
'''
soup = BeautifulSoup(html_content, 'html.parser')
print(soup.prettify())
执行结果:
<div data="你好" id="content">
<p>
测试01
</p>
<span>
测试02
</span>
</div>
<div>
测试03
</div>