代码示例:
from bs4 import BeautifulSoup
html_content = '''
<script>a</script>
你好啊<p>hi</p>
<script>b</script>
'''
soup = BeautifulSoup(html_content, 'html.parser')
for s in soup('script'):
s.extract()
new_html_content = str(soup)
print(new_html_content)
运行结果:
你好啊<p>hi</p>