Skip to content

Instantly share code, notes, and snippets.

@TheCodedSelf
Created April 10, 2018 16:25
Show Gist options
  • Save TheCodedSelf/848bd2cabc2087aae219aac876336b4c to your computer and use it in GitHub Desktop.
Save TheCodedSelf/848bd2cabc2087aae219aac876336b4c to your computer and use it in GitHub Desktop.
Scrape a web page for any email addresses
import urllib2, re
def find_email(url):
hdr = {'User-Agent': 'Mozilla/5.0'}
req = urllib2.Request(url, headers=hdr)
try:
f = urllib2.urlopen(req)
s = f.read()
emails = re.findall(r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}",s)
return emails
except:
return 'error'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment