使用BeautifulSoup解码html实体

kec*_*ito 5 python beautifulsoup

我试图使用BeautifulSoup解码实体,但没有运气.

from BeautifulSoup import BeautifulSoup

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

print decoded
Run Code Online (Sandbox Code Playgroud)

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

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

Gab*_*aru 2

你需要print decoded.contents

>>> print decoded
<p> </p>
>>> print decoded.contents
[u'<p> </p>']
Run Code Online (Sandbox Code Playgroud)