-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnyToIdn.py
More file actions
41 lines (35 loc) · 1.39 KB
/
Copy pathAnyToIdn.py
File metadata and controls
41 lines (35 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
#coding=utf8
#from __future__ import unicode_literals
import idna
import json
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
def TextToIdna(yourfile):
lines=[]
with open(yourfile, 'r') as f:
for line in f:
lines.append(line.strip())
#把文本的每一行读取出来保存成一个列表
tmplist=[]
for l in lines:
str1 = l.encode('raw_unicode_escape').split('.')
tmplist.append(str1)
#针对大列表里的字段再根据.分割成小列表,这样保证每一行是一个小列表,这两段for循环可以写成一个
for j in tmplist: #循环大列表
jlist=[]
for h in j: #循环小列表,相当于处理每一行文本数据
if h.startswith('xn--'):
tt = idna.decode(h)
jlist.append(tt)
else:
jlist.append(h)
print '.'.join(jlist) #每一行的内容是一个列表,合成一个文本字符串
if __name__ == '__main__':
'''
读取一个文件文件,每一行文本的内容是一个域名,而且域名当中会在不定的位置出现punycode,因此需要将凡是出现punycode都转换成中文
The Script be used from file each line to ZW,when each line contains puny code anyway,It can be normal runing....................
'''
yourfile=sys.argv[1]
TextToIdna(yourfile)