Getting emails from a URL with urllib2

In this example we can see how extract emails using urllib2 and regular expressions.

You can find the following code in the get_emails_from_url.py file:

import urllib2
import re
#enter url
web = raw_input("Enter url: ")
#https://www.packtpub.com/books/info/packt/terms-and-conditions
#get response form url
response = urllib2.Request('http://'+web)
#get content page from response
content = urllib2.urlopen(response).read()
#regular expression
pattern = re.compile("[-a-zA-Z0-9._]+@[-a-zA-Z0-9_]+.[a-zA-Z0-9_.]+")
#get mails from regular expression
mails = re.findall(pattern,content)
print(mails)

In this screen capture, we can see the script in execution for the packtpub.com domain:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.216.75