result = re.sub('&#(\\d+);', lambda m: '&#{n};'.format(n=ord(chr(int(m.
    group(1))).encode('cp1252'))), lh.tostring(doc))
print(result)
Using python to edit html, but lxml converts nice html entities to strange encoding