# -*- coding: utf-8 -*- """ Created on Sun Dec 15 14:08:03 2019 @author: Dell 提取包含QQ号的文本为QQ邮箱,并保存到文件 """ import re import tkinter qqstr = "请在这里粘贴需要提取的包含QQ号的文本" baklist = None def extract(): """提取所有QQ号码为邮箱""" #全部提取文本域的内容 content = text.get("0.0", "end") qqlist = re.findall("[1-9]\\d{4,10}", content) global baklist baklist = [] for qq in qqlist: qq += "@qq.com" baklist.append(qq) listbox.insert(tkinter.END, qq) def save(): """保存提取邮箱到文件""" path = r"E:\TextMining\面向对象\正则表达\QQ邮箱.txt" file = open(path, "wb") if baklist != None: for email in baklist: line = (email + "\r\n").encode("utf=8") file.write(line) file.close() print("已保存到: %s,请查收" % path) win = tkinter.Tk() win.title("QQ邮箱提取工具") #提取按钮 btn = tkinter.Button(win, text="提取为邮箱", command=extract) btn.pack() #保存按钮 btn1 = tkinter.Button(win, text="保存到文件", command=save) btn1.pack() #粘贴被提取的文本内容 text = tkinter.Text(win) text.insert(tkinter.INSERT, qqstr) text.pack() #保存提后的列表 listbox = tkinter.Listbox(win, width=80) listbox.pack() win.mainloop()
来源:https://www.cnblogs.com/zxfei/p/12044354.html