Hello there below is the easy way to get the email addresses extracted from any file.

import os
import re
import sys

def grab_email(file):
"""Try and grab all emails addresses found within a given file."""
email_pattern = re.compile(r'\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b',re.IGNORECASE)

found = set()
if os.path.isfile(file):
for line in open(file, 'r'):
found.update(email_pattern.findall(line))
for email_address in found:
print email_address
if __name__ == '__main__':grab_email(sys.argv[1])

Usage:
For example lets assume I have named the source code as extract.py and the file from which data is to be extracted is named as 01.html .

Now go to the shell and type

python extract.py 01.html

And thats all you have to do..
Have fun hacking this code.

You have messed up your indention!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.