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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# 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) |
Now you can execute the python script app.py
and then you will see the following result