Python识别文件中的手机号
2022/8/16 1:26:40
本文主要是介绍Python识别文件中的手机号,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
# 代码识别文件中的所有手机号 import re # 读取目标文本文件 def get_str(path): f = open(path, encoding='utf-8') data = f.read() f.close() return data # 正在表达式提取文本号码 def get_phone_number(str): res = re.findall(r'(?:13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}', str) return res # 保存得到的号码 def save_res(res, save_path): save_file = open(save_path, 'w') for phone in res: save_file.write(phone) save_file.write('\n') save_file.write('\n号码共计:' + str(len(res))) save_file.close() print('号码读取结束,号码共计:' + str(len(res))) path = r'C:Desktop\qwe\手机号.txt' # 待读取的文档 save_path = r'C:Desktop\qwe\提取结果.txt' # 保存提取的手机号 text = get_str(path) res = get_phone_number(text) save_res(res, save_path) print('...处理完成..')
这篇关于Python识别文件中的手机号的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python
- 2024-03-12python colon equals