python实现php中strip_tags的功能
import bleach
def strip_tags(html, tags=None):
# 使用bleach库的clean函数去除HTML标签并保留指定标签
return bleach.clean(html, tags=tags, strip=True)
# 示例用法
html = '<p>This is a <b>bold</b> text.</p>'
stripped_text = strip_tags(html, tags=['b'])
print(stripped_text)
评论已关闭