Python で実体参照のデコード。アポストロフィーの場合…

まず、デコードの定石??

ググって見っけたやつ。
文字実体参照 → htmlentitydefs.name2codepoint → 数値文字参照 → unichr() → Unicode 文字列

はまったorz

アポストロフィーの文字実体参照(')は XHTML1.0 からだとか…

>>> import htmlentitydefs
>>> htmlentitydefs.name2codepoint['apos']
Traceback (most recent call last):
  ...
KeyError: 'apos'

とりあえず

これでいいのかな

>>> from xml.sax.saxutils import unescape
>>> unescape('' " & < >')
'&apos; &quot; & < >'
>>> unescape('&apos; &quot; &amp; &lt; &gt;', {'&apos;': '\'', '&quot;': '"'})
'\' " & < >'

via EscapingXml - Python Wiki