xyhhx
xyhhx

Reputation: 6674

Convert symbol to HTML entity

I have a Python script (source here) to convert symbols to HTML entities (it will be used in a scraper).

When I run this script, it spits me back out the copyright symbol. Others run this and it works as expected. I may have mis-tagged it

Upvotes: 1

Views: 118

Answers (1)

tynn
tynn

Reputation: 39853

You're using the str representations. The script works perfectly fine with Python 3 since str is the unicode type. In Python 2 str is comparable to the new bytes type and © in its UTF-8 representation is a two byte character.

So better use unicode everywhere, just like u"©" and a.decode('utf-8').

Upvotes: 3

Related Questions