开发者

From escaped html -> to regular html? - Python

I used BeautifulSoup to handle XML files that I have collected through a REST API.

The responses contain HTML code, but BeautifulSoup escapes all the HTML tags so it can be displayed nicely.

Unfortunately I need the HTML code.


How would I go on about transforming the escaped HTML into proper markup?


Help would be very much appre开发者_开发知识库ciated!


I think you want xml.sax.saxutils.unescape from the Python standard library.

E.g.:

>>> from xml.sax import saxutils as su
>>> s = '<foo>bar</foo>'
>>> su.unescape(s)
'<foo>bar</foo>'


You could try the urllib module?

It has a method unquote() that might suit your needs.

Edit: on second thought, (and more reading of your question) you might just want to just use string.replace()

Like so:

string.replace('&lt;','<')
string.replace('&gt;','>')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜