如何使用python检查文件是否包含电子邮件地址或md5
下载后如何检查源文件是否包含电子邮件地址或md5如何使用python检查文件是否包含电子邮件地址或md5,python,pandas,Python,Pandas,下载后如何检查源文件是否包含电子邮件地址或md5 data2 = pd.read_csv(source_file, header=None) 尝试使用regrex和str.contains…但无法确定如何继续 如果这是检查,然后根据这一点,我需要继续为脚本的其余部分 source_file1: abd@gmail.com xyz@gmail.com source_file2: d131dd02c5e6vrc4 55ad340609f4fw02 到目前为止,我已经尝试: if(data2
data2 = pd.read_csv(source_file, header=None)
尝试使用regrex和str.contains…但无法确定如何继续
如果这是检查,然后根据这一点,我需要继续为脚本的其余部分
source_file1:
abd@gmail.com
xyz@gmail.com
source_file2:
d131dd02c5e6vrc4
55ad340609f4fw02
到目前为止,我已经尝试:
if(data2['email/md5'].str.contains(r'[a-zA-Z0-9._-]+@[a-zA-Z.]+')==1): print "yes"
如果我很理解这个问题,你有两个文件,你想自动检测哪个有电子邮件地址,哪个有md5
import re
import re
with open(source_file1, 'r') as f:
line = f.readline()
while not line:
line = f.readline()
#First line not empty containing a mail address
if re.match('[^@]+@[^@]+\.[^@]+', f.readline()):
mail_source_file = source_file1
md5_source_file = source_file2
else:
md5_source_file = source_file1
mail_source_file = source_file2
mail_dataframe = pd.read_csv(mail_source_file, header=None)
md5_dataframe = pd.read_csv(md5_source_file, header=None)
这有用吗 试试这个模式
r'@\w+\.com'
Ex:
import pandas as pd
df1 = pd.read_csv(filename1, names=['email/md5'])
if df1['email/md5'].str.contains(r'@\w+\.com').all():
print("Email")
else:
print("md5")
考虑到哈希为16个字母数字符号,并且没有无效电子邮件,这可能会起作用:
with open('file.txt', 'r') as myfile:
getFile = myfile.read()
# Emails
numberOfEmails = len(re.findall(r'@(.*?).com', getFile))
print "%d email(s) found"%(numberOfEmails)
# MD5
hashFormatCnt = 0
splitFile = getFile.split()
for str in splitFile:
if re.match('^[\w-]+$', str):
if len(str) == 16:
hashFormatCnt = hashFormatCnt + 1
print "%d look like hash found"%(hashFormatCnt)
你需要更具体一些 如果你想知道电子邮件的外观,你可以看到它
如果你想知道md5的外观,它通常用32个十六进制数字来表示(0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f)。你用正则表达式做过什么?if(data2['email/md5'].str.contains(r'[a-zA-Z0-9.-]+@[a-zA-Z.]+')==1):打印“是”我是这样从ftp下载文件的:ftp.retrbinary(“RETR”+源文件,开源文件,'wb').write)data2=pd.read\u csv(source\u file,header=None)从这个data2我需要检查电子邮件和md5