-
Notifications
You must be signed in to change notification settings - Fork 1
/
emailhunt.py
57 lines (49 loc) · 1.46 KB
/
emailhunt.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import urllib.request
import re
def find_email(word):
# word = word.strip('<br>')
word = re.sub('<br>', '', word)
word = word.rstrip('.?,')
word = re.sub('NOSPAM', '', word)
if 'mailto:' in word:
word = re.search('mailto:(.*)">', word).group(1)
return word
stream = urllib.request.urlopen('http://cs1110.cs.virginia.edu/emails.html')
valid_domains = ['.edu','.com','.ca','.us','.rentals']
all_words = []
for line in stream:
decoded = line.decode('UTF-8').strip()
words = decoded.split(' ')
for word in words:
all_words.append(word)
# p = re.compile('[a]')
# print(p.match("abcd").group())
final_list = []
for i in range(0,len(all_words)):
word = all_words[i]
if '@' in word:
final = find_email(word)
#print(final)
if '.' in final[final.index('@'):]:
if final[final.rfind('.'):].lower() in valid_domains:
final_list.append(final)
elif word == 'at':
first = all_words[i-1]
last = all_words[i+1]
dot_check = ''
if all_words[i+2] == 'dot':
dot_check = '.' + all_words[i+3]
#print(first)
string = first + '@' + last + dot_check
final = find_email(string)
#print(final)
if not final == 'at':
if '.' in final[final.index('@'):]:
final_list.append(final)
s = []
for i in final_list:
if i not in s:
s.append(i)
for i in s:
print(i)
#print(decoded)