使用Python检查Email地址列表
Feb
13
使用Python检查Email地址列表
有个email地址的列表文件,大概有6W多个吧,打算用来做群发的(每一行一个email地址),可是发现得到的email地址中有不少有问题,比如写成了aaa@aaa.com@ccc,还有些包含特殊的字符等等
6W多行的文件,手动一个个的去进行检查,那要到猴年马月啊???
何不用程序来进行呢?刚好正在学习Python,用来练习一下也不错,以下的是简单的代码,只实现了简单的检查错误的功能,并把错误的地址写入一个文件中,如何用程序自动去纠正这些错误的地址,恐怕对我而言比较困难
# -*- coding: utf-8 -*-
import sys,os,re filedir=“/tmp/checkemail”
file=filedir+“/email_list”
errfile=filedir+“/error_email”def checkemail():
????f=open(file,‘r’)
????lines=f.readlines()
????for line in lines:
????????line1=line[:-1]
????????p=re.compile(r‘^[_a-z0-9-]+(\.[a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$’)
????????a=p.match(line)
????????if a==None:
????????????err=open(“errfile”,‘a’)
????????????err.write(line)
????????????????????else:
????????????passif __name__ == ‘__main__’:
????checkemail()


















No Comments »
No comments yet.
RSS feed for comments on this post. TrackBack URI
Leave a comment
If you want to leave a feedback to this post or to some other user´s comment, simply fill out the form below.