• 本节内容的数据见电脑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
'''
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐