0

(编辑:现在引用Unbaking mojibake

源文件:Android 手机 .vcf 联系人文件目标:Windows 7 用户联系人文件(导入的 .vcf)

生成的联系信息:名称字段的韩国 mojibake:'_곗퐫 李쏀__ㅻ━肄섏떎留_'

结果应该只有韩文文本。经过一番研究,我猜测EUC-kr由于mojibake中的汉字而存在一些编码问题。但是真的不知道...

使用从Unbaking mojibake修改的代码

这是 Python 结果:_°ì¤Ô¤½¤É¤§ ì°½í__¤ë¦¬ì½¤Ô¤µ¤Â¤°¤Ô¤¨¤¤«ë§_

显然这是不正确的。所以还是卡住了...

# ?'windows-1252' -> 949?
encoding1 = 'ISO-2022-KR' #could not encode
encoding1 = 'windows-1252' #could not encode
encoding1 = 'iso-8859-1' #could not encode
encoding1 = 'utf8' #does nothing
encoding1 = 'euc-kr'

import chardet

import chardet
import codecs

mojibake = '_곗퐫 李쏀__ㅻ━肄섏떎留_'

try:
    encoded_str = mojibake.encode(encoding1)
except UnicodeEncodeError:
    print("error: could not encode")
    encoded_str = None

if encoded_str:
    detected_encoding = chardet.detect(encoded_str)["encoding"]
    print('detected_encoding',detected_encoding)
    try:
        correct_str = encoded_str.decode(detected_encoding)
    except UnicodeEncodeError:
        print("could not decode encoded_str as", detected_encoding)

    print(correct_str)
4

0 回答 0