原理
什么是 IDN?
国际化域名 (Internationalized Domain Name,IDN) 又名特殊字符域名, 是指部分或完全使用特殊文字或字母组成的互联网域名, 包括中文, 发育, 阿拉伯语, 希伯来语或拉丁字母等非英文字母, 这些文字经过多字节万国码编码而成. 在域名系统中, 国际化域名使用 punycode 转写并以 ASCII 字符串存储.
什么是 idna?
- A library to support the Internationalised Domain Names in Applications (IDNA) protocol as specified in RFC 5891. This version of the protocol is often referred to as "IDNA2008" and can produce different results from the earlier standard from 2003.
- >>> import idna
- >>> print(idna.encode(u'ドメイン. テスト'))
结果: xn--eckwd4c7c.xn--zckzah
>>> print idna.decode('xn--eckwd4c7c.xn--zckzah')
结果: ドメイン. テスト
Demo:
? 这个字符, 如果使用 python3 进行 idna 编码的话
print('?'.encode('idna'))
结果
b'c/u'
如果再使用 utf-8 进行解码的话
print(b'c/u'.decode('utf-8'))
结果
c/u
通过这种方法可以绕过网站的一些过滤字符
来源: http://www.bubuko.com/infodetail-3189417.html