|
本帖最后由 duquancai 于 2019-2-11 23:46 编辑
- # -*- coding: utf-8 -*-
- import re, os, collections
- my_set = set()
- r = re.compile(r'(?=(1[3578]\d{9}))')
- def get_mobile(text):
- my_set.add(text.group(1))
- def getAllDirQU(path):
- queue=collections.deque()
- queue.append(path)
- while len(queue)!=0:
- dirPath=queue.popleft()
- for fileName in os.listdir(dirPath):
- fileAbapath=os.path.join(dirPath,fileName)
- if os.path.isdir(fileAbapath):
- queue.appendleft(fileAbapath)
- else:
- get_str(fileAbapath)
- def get_str(path):
- try:
- with open(path, 'rb') as f:
- data = f.read()
- my_str = data.decode('ascii',errors='ignore')
- r.sub(get_mobile, my_str)
- except:
- pass
- if __name__ == '__main__':
- path = r'C:\Users\ADU\Desktop\示例样本'
- getAllDirQU(path)
- print(my_set)
复制代码 |
评分
-
1
查看全部评分
-
|