代码拉取完成,页面将自动刷新
import re
def validate_email(email):
pattern=r'^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,}$'
return bool(re.match(pattern,email))
def classify_email(email):
if email.find(".edu")!=-1 or email.find(".ac.")!=-1:
return "教育机构"
elif email.find(".com")!=-1 or email.find(".org")!=-1 or email.find(".net")!=-1:
return "公司"
else:
return "个人"
def extract_email_parts(email):
username,domain=email.split("@",1)
tld=domain.split(".")[-1]
return {
'用户名': username,
'域名': domain,
'TLD': tld
}
def obfuscate_email(email):
parts=re.split(r'@',email)
username, domain = parts
if len(username) > 1:
obfuscated_username = f"{username[0]}***{username[-1]}"
else:
obfuscated_username = username+"***"
last_dot_index = domain.rfind(".")
second_last_dot_index = domain[:last_dot_index].rfind(".") if last_dot_index != -1 else -1
if second_last_dot_index != -1:
obfuscated_domain = f"**{domain[second_last_dot_index + 1:]}"
else:
obfuscated_domain = f"**{domain}"
return f"{obfuscated_username}@{obfuscated_domain}"
test_emails = [
"user.name@university.ac.edu",
"john.doe+test@example.com",
"invalid.email@.com",
"another_user@sub.domain.org",
"private@gmail.com"
]
for item in test_emails:
cnt=0
print("测试邮箱:",item)
if validate_email(item):
print("验证结果:有效")
else:
print("验证结果:无效")
print("---------------------------------")
continue
print("分类结果:",classify_email(item))
print("提取信息:",end="")
for i,v in extract_email_parts(item).items():
cnt+=1
if cnt==3:
print(i,"=",v)
else:
print(i,"=",v,end=",")
print("脱敏处理:",obfuscate_email(item))
print("---------------------------------")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。