0

I've been trying to find an online converter, or Python3 function, for conversion of email addresses in the html+hex format, such as: %69%6efo ---> info

%69 : i
%6e : n
&#64 : @
(source: http://www.asciitable.com/)

...and so on..

All the following sites are not converting both hex and html codes combined in the "word":

https://www.motobit.com/util/charset-codepage-conversion.asp
https://www.binaryhexconverter.com/ascii-text-to-binary-converter
https://www.dcode.fr/ascii-code
http://www.unit-conversion.info/texttools/ascii/
https://mothereff.in/binary-ascii

I'd appreciate any recommendations. Txs.

fana it
  • 53
  • 2
  • 11

1 Answers1

1

Try html.unescape() or HTMLParser#unescape, depending on which version of Python you are using: https://stackoverflow.com/a/2087433/2675670

Since this is a mix of hex values and regular characters, I think we have to come up with a custom solution:

word = "%69%6efo"

while word.find("%") >= 0:
    index = word.find("%")
    ascii_value = word[index+1:index+3]
    hex_value = int(ascii_value, 16)
    letter = chr(hex_value)
    word = word.replace(word[index:index+3], letter)

print(word)

Maybe there's a more streamlined "Pythonic" way of doing this, but it works for the test input.

Richard
  • 2,226
  • 2
  • 19
  • 35
  • txs @Richard, it solved part of my question, related to html code... I still need to find a way for the rest of it, such as %69%6efo@.... – fana it Feb 23 '19 at 18:59