从转义的html - >到常规html? - Python [英] From escaped html -> to regular html? - Python
本文介绍了从转义的html - >到常规html? - Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用BeautifulSoup处理通过REST API收集的XML文件。
I used BeautifulSoup to handle XML files that I have collected through a REST API.
响应包含HTML代码,但BeautifulSoup转义所有HTML标签,以便它可以显示得很好。
The responses contain HTML code, but BeautifulSoup escapes all the HTML tags so it can be displayed nicely.
不幸的是我需要HTML代码。
Unfortunately I need the HTML code.
如何将转义的HTML转换成适当的标记?
How would I go on about transforming the escaped HTML into proper markup?
帮助将非常感谢! / p>
Help would be very much appreciated!
推荐答案
我想你想要 xml.sax.saxutils.unescape 从Python标准库。
I think you want xml.sax.saxutils.unescape from the Python standard library.
例如:
>>> from xml.sax import saxutils as su
>>> s = '<foo>bar</foo>'
>>> su.unescape(s)
'<foo>bar</foo>'
这篇关于从转义的html - >到常规html? - Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文