I am trying to parse emails from web page. my code:
import urllib2,cookielib
import re
site= "http://www.traidnt.net/vb/traidnt207743"
hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Accept-Encoding': 'none',
'Accept-Language': 'en-US,en;q=0.8',
'Connection': 'keep-alive'}
req = urllib2.Request(site, headers=hdr)
page = urllib2.urlopen(req)
content = page.read()
links = re.findall('mailto:.+?@.+.', content)
for link in links:
print link[7:-1]
and the result come like:
email1@
email2@
email3@
...
but i need to get all emails with complete form. Please how i can do that to get complete form of all emails.
Thank you!
I just added the following code to your code and it works perfectly:
regexp = re.compile(("mailto:([a-z0-9!#$%&'*+\/=?^_`{|}~-]+@[a-z0-9]+\.[a-zA-Z0-9-.]+)"))
links = re.findall(regexp, content)
print links
Output:
['njm-kwt@hotmail.com', 'fnan-ksa@hotmail.com', 'k-w-t7@hotmail.com', 'coool-uae@hotmail.com', 'qsd@hotmail.de', 'o1ooo@hotmail.de', 'm-p-3@hotmail.de', 'ya7oo@hotmail.de', 'g5x@hotmail.de', 'f7t@hotmail.de', 'm2y@hotmail.de', 's2udi@hotmail.de', 'q2tar@hotmail.de', 'kuw2it@hotmail.de', 's2udi@hotmail.fr', 'qxx@hotmail.de', 'y-e-s@hotmail.de', 'y-a@hotmail.de', 'qqj@hotmail.de', 'qjj@hotmail.de', 'admin_vb@hotmail.de', 'eng-vb@hotmail.com', 'a3lantk@hotmail.com', 'a3lnkm@hotmail.com', 't7t@hotmail.de', 'mohamed_fathy41@hotmail.com', 'ox-9@hotmail.com', 'ox-9@hotmail.com']