python - 使用 BeautifulSoup 解码 html 实体

标签 python beautifulsoup

我正在尝试使用 BeautifulSoup 解码实体,但没有成功。

from BeautifulSoup import BeautifulSoup

decoded = BeautifulSoup("<p> </p>",convertEntities=BeautifulSoup.HTML_ENTITIES)

print decoded

输出根本没有解码。我在这里找到了很多使用这种方法的答案。 我做错了什么吗?

我想为此使用 BeautifulSoup,所以请不要费心告诉我标准库有解码实体的方法。

最佳答案

您需要print decoded.contents :

>>> print decoded
<p> </p>
>>> print decoded.contents
[u'<p> </p>']

关于python - 使用 BeautifulSoup 解码 html 实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10088318/

相关文章:

python - 子字符串列表与字符串列表的 bool 比较

python - 逐行处理内存中的文件并像python中的对象一样生成文件

python - 用标签替换字符串中的单词

Python,美汤,获取所有类名

python - 在 Python 中阻止 GET 请求的解决方法

python - 使用 Django 在 AWS 上使用 EC2 对 Websockets 进行故障排除

python - 从 csv.dictreader 排序和过滤数据

python - 函数在应该返回 True 时返回 false。编码问题?

selenium - 使用 Python 从 JSP 网站抓取表

python - Pamie 和 python-win32 问题 pamie3 不工作