w3lib.html.remove_tags
安装第三方包
pip install w3lib
使用
from w3lib.html import remove_tagss = '<h1><p>hello <i>world</i></p></h1>'print(remove_tags(s))# hello worldprint(remove_tags(s, which_ones=('p','i'))) # 指定要移除的tags# <h1>hello world</h1>print(remove_tags(s, keep=('p','i'))) # 指定要保留的tags# <p>hello <i>world</i></p>
