正则表达式提取文件里的邮箱或手机号(数据分析案例一)
·
- 本节内容的数据见电脑F:\python数据\Python海量数据(精缩版) 或 百度网盘“我的数据文件/Python海量数据”

提取文件里的邮箱或手机号
import re
filepath="E:\python数据分析\百度网盘\Python数据分析海量数据营销day1\Python数据分析海量数据营销day1\腾讯通讯录\QQ-腾讯通讯录.txt"
tencentfile=open(filepath,"rb")
lasttext=tencentfile.read()
tencentfile.close()
lasttext=lasttext.decode("utf-8","ignore")
regexmail=re.compile("([A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4})",re.IGNORECASE)
maillist=regexmail.findall(lasttext)
for mail in maillist:
print(mail)
'''
ponyma@tencent.com
szponyma@public.szptt.net.cn
tony@tencent.com
'''
import re
filepath="E:\python数据分析\百度网盘\Python数据分析海量数据营销day1\Python数据分析海量数据营销day1\腾讯通讯录\QQ-腾讯通讯录.txt"
tencentfile=open(filepath,"rb")
lasttext=tencentfile.read()
tencentfile.close()
lasttext=lasttext.decode("utf-8","ignore")
regexmail=re.compile("1[34578]\d{9}",re.IGNORECASE)
maillist=regexmail.findall(lasttext)
for mail in maillist:
print(mail)
'''
13809899900
13802200907
13902984686
13808800800
'''
更多推荐
所有评论(0)