Python 3 Script to Extract to Extract Email-id From URL Text File Using Python Regex and Pattern Matching and urllib Library Full Tutorial For Beginners

Python 3 Script to Extract to Extract Email-id From URL Text File Using Python Regex and Pattern Matching and urllib Library Full Tutorial For Beginners

 

Welcome folks today in this blog post we will be  extracting email id from url text file. All the source code of the application is given below.

 

 

 

Requirements

 

 

In order to proceed you need a working version of python

 

 

 

#  Source Code

 

 

Now create a app.py file and copy paste the following code

 

 

app.py

 

 

 

# library that handles the URL stuff 
import urllib.request 

# Importing module required for 
# regular expressions 
import re 

# Assign urlopen to a file object variable 
fhand = urllib.request.urlopen 
    ('https://media.geeksforgeeks.org/wp-content/uploads/e-mail-1.txt') 

for line in fhand: 
    # Getting the text file 
    # content line by line. 
    s = line.decode().strip() 

    # regex for extracting all email-ids 
    # from the text file 
    reg = re.findall(r"[A-Za-z0-9._%+-]+"
                    r"@[A-Za-z0-9.-]+"
                    r"\.[A-Za-z]{2,4}", s) 

    # printing the list output 
    print(reg)

 

See also  Python 3 WxPython HTML Help Dialog Popup Menu in GUI Desktop App Full Project For Beginners

 

Now you can execute the python script app.py and then you will see the following result

 

 

 

 

 

Leave a Reply