Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Convert XML/HTML Entities into Unicode String in Python [duplicate]

I'm doing some web scraping and sites frequently use HTML entities to represent non ascii characters. Does Python have a utility that takes a string with HTML entities and returns a unicode type?

For example:

I get back:

ǎ

which represents an "ǎ" with a tone mark. In binary, this is represented as the 16 bit 01ce. I want to convert the html entity into the value u'\u01ce'

Answer*

Draft saved
Draft discarded
Cancel
2
  • Be careful though, because this can also return an object of type str if there is no special character. Commented Oct 20, 2014 at 20:02
  • best solution when everything fails, only lxml comes to rescue. :) Commented Nov 20, 2016 at 21:18

default

AltStyle によって変換されたページ (->オリジナル) /