在 Python 字符串中解碼 HTML 實體? - Decode HTML entities in Python string?

問題:

I'm parsing some HTML with Beautiful Soup 3, but it contains HTML entities which Beautiful Soup 3 doesn't automatically decode for me:我正在使用 Beautiful Soup 3 解析一些 HTML,但它包含 Beautiful Soup 3 不會自動爲我解碼的 HTML 實體:

>>> from BeautifulSoup import BeautifulSoup

>>> soup = BeautifulSoup("<p>&pound;682m</p>")
>>> text = soup.find("p").string

>>> print text
&pound;682m

How can I decode the HTML entities in text to get "£682m" instead of "&pound;682m" .如何解碼text的 HTML 實體以獲得"£682m"而不是"&pound;682m"


解決方案:

參考一: https://en.stackoom.com/question/8l1G
參考二: https://stackoom.com/question/8l1G
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章