top of page
  • Writer's pictureQuan Sheng

Email on python

I am currently exploring more on the programming side instead of the Pi components.


Email Scraping

- Today I will be doing email-related activity on python!


Python code:


import urllib.request,re # re is regular expression

f = urllib.request.urlopen("http://www.reach.org.sg/index.php/contact-us")

s = f.read().decode('utf-8') # download the entire page

# specify the regex for finding emails and return as a set

emails = set(re.findall(r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}",s))

# print all the emails

for e in emails:

print(e)


In this python programming, it is capable to scrape email from the website indicated.

f = urllib.request.urlopen("http://www.reach.org.sg/index.php/contact-us")

In this line, it requests a webform library response.

and decoding the webpage into a utf-8


emails = set(re.findall(r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}",s))

it will search for the email regex condition.

The email is stored into the list, therefore by printing out, I can see the result that has been scraped!


Isn't it cool to be able to do this?


By sometimes people use this method to harvest email and can be used for illegal activities such as sending spam email and etc.


2 views

Comentários


bottom of page