python - quopri模块 - vcf格式文件中quoted-printable编码转utf-8

QUOTED-PRINTABLE是邮件常用的编码方式, python中有一个对应的模块:quopri

从手机里导出的vcf是这样的格式:

BEGIN:VCARD
VERSION:2.1
N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:;=E5=B7=A5=E4=BC=9A=E7=9B=9F=E7=BB=8F=E6=B5=8E;;;
FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=E5=B7=A5=E4=BC=9A=E7=9B=9F=E7=BB=8F=E6=B5=8E
TEL;CELL:3000000100
END:VCARD
BEGIN:VCARD
VERSION:2.1
N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:;=E5=B7=A5=E4=BC=9A=E9=98=BF=E6=97=97=E5=B8=B8;;;
FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=E5=B7=A5=E4=BC=9A=E9=98=BF=E6=97=97=E5=B8=B8
TEL;CELL:3000000101
END:VCARD

反编译:

import quopri
RES = quopri.decodestring('=E5=B7=A5=E4=BC=9A=E7=9B=9F=E7=BB=8F=E6=B5=8E').decode('utf-8')
print(f"RES = {RES}")  # 输出:RES = 工会盟经济

编译:

import quopri
res = quopri.encodestring('工会盟经济'.encode())
print(f"res = {res}")  # 输出: res =b'=E5=B7=A5=E4=BC=9A=E7=9B=9F=E7=BB=8F=E6=B5=8E'

参考链接:https://blog.csdn.net/u011480883/article/details/103079806

你可能感兴趣的:(python,vcf,quopri,quoted,printable,utf-8)