1.使用BeautifulSoup库

from bs4 import BeautifulSoup

def remove_html_tags(html):
    soup = BeautifulSoup(html, 'html.parser')
    text = soup.get_text()
    return text

2. 使用正则表达式

import re

def remove_html_tags(html):
    clean = re.compile('<.*?>')
    text = re.sub(clean, '', html)
    return text

测试

html = '<p>Hello, <strong>world</strong>!</p>'
text = remove_html_tags(html)
print(text)  # 输出: Hello, world!