Home  >  Article  >  Backend Development  >  python去除所有html标签的方法

python去除所有html标签的方法

WBOY
WBOYOriginal
2016-06-10 15:13:131930browse

本文实例讲述了python去除所有html标签的方法。分享给大家供大家参考。具体分析如下:

这段代码可以用于去除文本里的字符串标签,不包括标签里面的内容

import re
html='<a href="http://www.jb51.net">脚本之家</a>,Python学习!'
dr = re.compile(r'<[^>]+>',re.S)
dd = dr.sub('',html)
print(dd)

运行结果如下:

脚本之家,Python学习!

希望本文所述对大家的Python程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn