滤除HTML标签并在python中解析实体 [英] Filter out HTML tags and resolve entities in python

查看:115
本文介绍了滤除HTML标签并在python中解析实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为正则表达式会吓倒我,所以我试图找到一种方法来删除所有的HTML标签并从Python中的字符串中解析HTML实体。

Because regular expressions scare me, I'm trying to find a way to remove all HTML tags and resolve HTML entities from a string in Python.

推荐答案

使用 lxml 这是python最好的xml / html库。

Use lxml which is the best xml/html library for python.

import lxml.html
t = lxml.html.fromstring("...")
t.text_content()

如果您只想清理html外观lxml.html.clean 模块

And if you just want to sanitize the html look at the lxml.html.clean module

这篇关于滤除HTML标签并在python中解析实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆