python - SOLVED: Python3 Convert all characters to HTML Entities -
i'm using python3 , wonder if there module or default function converting characters of text html entities (even letters , digits) because don't want make translation map this.
later edit: @justhalf told me, found solution making function:
def htmlentities( string ): return ''.join(['&#{0};'.format(ord(char)) char in string])
html.parser
job
>>> import html.parser >>> h = html.parser.htmlparser() >>> print(h.unescape('£682m')) £682m >>> print(h.escape('£682m')) £682m
or if want escape characters, can replace each character ordinals:
''.join('&%d;'.format(ord(x)) x in string)
Comments
Post a Comment