Looking for email address | Python

#This program filter email accounts
import re, pyperclip

emailRegex = re.compile(r'''(
[a-zA-Z0-9._+-]+                        # username
@ # symbol
[a-zA-Z0-9.-]+                          # domain name
\.[a-zA-Z]{2,4}                         # dot something
)''', re.VERBOSE)

text = str(pyperclip.paste())
addMails = ''

for mails in emailRegex.findall(text):
    addMails += mails + '\n'

try:
    emailDoc = open('C:\\Users\\All users\\Desktop\\List_Of_Mails.txt', 'w')
    emailDoc.write('%s' % (addMails))
    emailDoc.close()
except Exception:
    emailDoc = open('List_Of_Mails.txt', 'w')
    emailDoc.write('%s' % (addMails))
    emailDoc.close()
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s