Strip HTML tags using Python
2013-01-15 16:29
274 查看
Strip HTML tags using Python
We often need to strip HTML tags from string (or HTML source). I usually do it using a simple regular expression in Python. Here is my function to strip HTML tags:def remove_html_tags(data):
p = re.compile(r'<.*?>')
return p.sub('', data)
Here is another function to remove more than one consecutive white spaces:
def remove_extra_spaces(data):
p = re.compile(r'\s+')
return p.sub(' ', data)
Note that re module needs to be imported in order to use regular expression.
相关文章推荐
- (python) Parsing certain HTML output tags using beautiful soup
- 安装 html2text - python下类似php的strip_tags
- Python 清理HTML标签相似PHP的strip_tags函数功能(二)
- Python 清理HTML标签类似PHP的strip_tags函数功能(二)
- Python 清理HTML标签类似PHP的strip_tags函数功能(二)
- rails 过滤掉所有的html标签 strip_tags
- strip_tags() --去除 HTML 及 PHP 的标签
- 去除html和php标记的方法--strip_tags
- PHP中使用strip_tags() 去除html标签
- php 去除html标记--strip_tags与htmlspecialchars的区别详解
- Python等同于PHP的 strip_tags?
- PHP strip_tags使用时需要使用的HTML系列函数
- python strip_tags 支持保留指定标签
- 移除HTML标签strip_tags()函数
- PHP strip_tags保留多个HTML标签的方法
- php 使用htmlspecialchars() 和strip_tags函数过滤HTML标签的区别
- rails 过滤掉所有的html标签 strip_tags
- PHP中strip_tags() 函数的使用方法和介绍,去除字符串中的HTML标签等
- Python 实现类似PHP的strip_tags功能,并能够定义他们自己的一套保留标记
- PHP 5.4 已废弃 magic_quotes_gpc,PHP安全转义函数详解(addslashes 、htmlspecialchars、htmlentities、mysql_real_escape_string、strip_tags)