pip install bleach python import bleach python bleach.clean(text, tags, attributes, styles, strip) python import bleach html = '<p>This is a <strong>sample</strong> HTML text.</p>' clean_html = bleach.clean(html) print(clean_html) This is a sample HTML text. python import bleach html = '<p>This is a <strong>sample</strong> HTML text with <span style="color:red;">styling</span>.</p>' clean_html = bleach.clean(html, tags=allowed_tags, attributes=allowed_attributes, strip=False) print(clean_html) HTML <p>This is a <span style="color:red;">styling</span>.</p>


上一篇:
下一篇:
切换中文