GangstaGraham
GangstaGraham

Reputation: 9375

Convert HTML Entity to Python Emoji

Say I have the following HTML emoji entity: '&#x1f604 ;'

Note there isn't actually a space between the 4 and the ; it's just there so that it doesn't show up as a smiley

The emoji's Python form is: u"\U0001f604"

How do I convert all HTML emoji entities to their Python form?


Things I have tried so far:

Upvotes: 2

Views: 1523

Answers (1)

Robᵩ
Robᵩ

Reputation: 168706

HTMLParser.unescape does just that:

In [3]: HTMLParser.HTMLParser().unescape( '😄' )
Out[3]: u'\U0001f604'

Upvotes: 5

Related Questions