从批量文本中提取所有电子邮件地址的python脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从批量文本中提取所有电子邮件地址的python脚本相关的知识,希望对你有一定的参考价值。
testing tool: http://www.pythonregex.com/
# this script will open a file with email addresses in it, then extract # those address and write them to a new file import os import re # vars for filenames filename = 'emaillist.txt' newfilename = 'emaillist-rev.txt' # read file if os.path.exists(filename): data = open(filename,'r') bulkemails = data.read() else: print "File not found." raise SystemExit # regex = [email protected] results = r.findall(bulkemails) emails = "" for x in results: emails += str(x)+" " # function to write file def writefile(): f = open(newfilename, 'w') f.write(emails) f.close() print "File written." # function to handle overwrite question def overwrite_ok(): response = raw_input("Are you sure you want to overwrite "+str(newfilename)+"? Yes or No ") if response == "Yes": writefile() elif response == "No": print "Aborted." else: print "Please enter Yes or No." overwrite_ok() # write/overwrite if os.path.exists(newfilename): overwrite_ok() else: writefile()
以上是关于从批量文本中提取所有电子邮件地址的python脚本的主要内容,如果未能解决你的问题,请参考以下文章
从Txt,PDf,Google云端硬盘中的Doc文件中提取电子邮件地址
在 Python 中使用 BeautifulSoup 从脚本标签中提取文本
JavaScript 从批量文本中提取电子邮件(使用正则表达式,JavaScript和jQuery)