使用BeautifulSoup解码html实体 [英] Decode html entities using BeautifulSoup

查看:168
本文介绍了使用BeautifulSoup解码html实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用BeautifulSoup解码实体,但是没有运气.

I am trying to decode entities using BeautifulSoup but with no luck.

from BeautifulSoup import BeautifulSoup

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

print decoded

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

The output is not decoded at all. I found a lot of answers here that use this method. Am I a doing something wrong?

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

I would like to use BeautifulSoup for this so please don't bother telling me that the standard library has a method to decode entities.

推荐答案

您需要 print decoded.contents :

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

这篇关于使用BeautifulSoup解码html实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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