Python从vcf文件中读取手机号并进行去重操作

文章目录

1. Python代码

file = open('test.vcf', 'r', encoding='utf-8')
tels = []
for line in file:
    line = line.strip('\n')
    contents = line.split(':')
    if contents[0] == 'TEL;TYPE=CELL':
        print(contents[1])
        tels.append(contents[1])
file.close()
# tels.append('13694091773')
# tels.append('13694091773')
tels = set(tels)  # 去重
for t in tels:
    print(t)
print(len(tels))

2. test.vcf文件内容

BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:13694091773
FN;CHARSET=gb2312:13694091773
TEL;TYPE=CELL:13694091773
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:15875485389
FN;CHARSET=gb2312:15875485389
TEL;TYPE=CELL:15875485389
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:15693286984
FN;CHARSET=gb2312:15693286984
TEL;TYPE=CELL:15693286984
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:13563128249
FN;CHARSET=gb2312:13563128249
TEL;TYPE=CELL:13563128249
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:18265015206
FN;CHARSET=gb2312:18265015206
TEL;TYPE=CELL:18265015206
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:15706380333
FN;CHARSET=gb2312:15706380333
TEL;TYPE=CELL:15706380333
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:18315080779
FN;CHARSET=gb2312:18315080779
TEL;TYPE=CELL:18315080779
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:18785350672
FN;CHARSET=gb2312:18785350672
TEL;TYPE=CELL:18785350672
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:15237807770
FN;CHARSET=gb2312:15237807770
TEL;TYPE=CELL:15237807770
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:15706478384
FN;CHARSET=gb2312:15706478384
TEL;TYPE=CELL:15706478384
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:15262696054
FN;CHARSET=gb2312:15262696054
TEL;TYPE=CELL:15262696054
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:13153906883
FN;CHARSET=gb2312:13153906883
TEL;TYPE=CELL:13153906883
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:13768250480
FN;CHARSET=gb2312:13768250480
TEL;TYPE=CELL:13768250480
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:13956836153
FN;CHARSET=gb2312:13956836153
TEL;TYPE=CELL:13956836153
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:15637432339
FN;CHARSET=gb2312:15637432339
TEL;TYPE=CELL:15637432339
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:15175799967
FN;CHARSET=gb2312:15175799967
TEL;TYPE=CELL:15175799967
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:18381919484
FN;CHARSET=gb2312:18381919484
TEL;TYPE=CELL:18381919484
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:18738018789
FN;CHARSET=gb2312:18738018789
TEL;TYPE=CELL:18738018789
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:18211301117
FN;CHARSET=gb2312:18211301117
TEL;TYPE=CELL:18211301117
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:15810563756
FN;CHARSET=gb2312:15810563756
TEL;TYPE=CELL:15810563756
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:13407564202
FN;CHARSET=gb2312:13407564202
TEL;TYPE=CELL:13407564202
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:15948438939
FN;CHARSET=gb2312:15948438939
TEL;TYPE=CELL:15948438939
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:15634919008
FN;CHARSET=gb2312:15634919008
TEL;TYPE=CELL:15634919008
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:13232208208
FN;CHARSET=gb2312:13232208208
TEL;TYPE=CELL:13232208208
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:18740063182
FN;CHARSET=gb2312:18740063182
TEL;TYPE=CELL:18740063182
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:15648381616
FN;CHARSET=gb2312:15648381616
TEL;TYPE=CELL:15648381616
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:13924987006
FN;CHARSET=gb2312:13924987006
TEL;TYPE=CELL:13924987006
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:15828014293
FN;CHARSET=gb2312:15828014293
TEL;TYPE=CELL:15828014293
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:15090865507
FN;CHARSET=gb2312:15090865507
TEL;TYPE=CELL:15090865507
END:VCARD
BEGIN:VCARD
VERSION:3.0
N;CHARSET=gb2312:13811231402
FN;CHARSET=gb2312:13811231402
TEL;TYPE=CELL:13811231402
END:VCARD
上一篇:06、flask---自定义URL


下一篇:存储过程