Easy way to extract email addresses from any file with python code. :
Hello there below is the easy way to get the email addresses extracted from any file.
#!/usr/bin/env python # coding: utf-8 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:
python 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.
















