forked from laramies/theHarvester
-
Notifications
You must be signed in to change notification settings - Fork 3
/
myparser.py
177 lines (156 loc) · 6.12 KB
/
myparser.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import string
import re
class parser:
def __init__(self, results, word):
self.results = results
self.word = word
self.temp = []
def genericClean(self):
self.results = re.sub('<em>', '', self.results)
self.results = re.sub('<b>', '', self.results)
self.results = re.sub('</b>', '', self.results)
self.results = re.sub('</em>', '', self.results)
self.results = re.sub('%2f', ' ', self.results)
self.results = re.sub('%3a', ' ', self.results)
self.results = re.sub('<strong>', '', self.results)
self.results = re.sub('</strong>', '', self.results)
for e in ('>', ':', '=', '<', '/', '\\', ';', '&', '%3A', '%3D', '%3C'):
self.results = string.replace(self.results, e, ' ')
def urlClean(self):
self.results = re.sub('<em>', '', self.results)
self.results = re.sub('</em>', '', self.results)
self.results = re.sub('%2f', ' ', self.results)
self.results = re.sub('%3a', ' ', self.results)
for e in ('<', '>', ':', '=', ';', '&', '%3A', '%3D', '%3C'):
self.results = string.replace(self.results, e, ' ')
def emails(self):
self.genericClean()
reg_emails = re.compile(
'[a-zA-Z0-9.-_]*' +
'@' +
'[a-zA-Z0-9.-]*' +
self.word)
self.temp = reg_emails.findall(self.results)
emails = self.unique()
return emails
def fileurls(self, file):
urls = []
reg_urls = re.compile('<a href="(.*?)"')
self.temp = reg_urls.findall(self.results)
allurls = self.unique()
for x in allurls:
if x.count('webcache') or x.count('google.com') or x.count('search?hl'):
pass
else:
urls.append(x)
return urls
def people_googleplus(self):
self.results = re.sub('</b>', '', self.results)
self.results = re.sub('<b>', '', self.results)
reg_people = re.compile('>[a-zA-Z0-9._ ]* - Google\+')
#reg_people = re.compile('">[a-zA-Z0-9._ -]* profiles | LinkedIn')
self.temp = reg_people.findall(self.results)
resul = []
for x in self.temp:
y = string.replace(x, ' | LinkedIn', '')
y = string.replace(y, ' profiles ', '')
y = string.replace(y, 'LinkedIn', '')
y = string.replace(y, '"', '')
y = string.replace(y, '>', '')
if y != " ":
resul.append(y)
return resul
def people_twitter(self):
reg_people = re.compile('(@[a-zA-Z0-9._ -]*)')
#reg_people = re.compile('">[a-zA-Z0-9._ -]* profiles | LinkedIn')
self.temp = reg_people.findall(self.results)
users = self.unique()
resul = []
for x in users:
y = string.replace(x, ' | LinkedIn', '')
y = string.replace(y, ' profiles ', '')
y = string.replace(y, 'LinkedIn', '')
y = string.replace(y, '"', '')
y = string.replace(y, '>', '')
if y != " ":
resul.append(y)
return resul
def people_linkedin(self):
reg_people = re.compile('">[a-zA-Z0-9._ -]* \| LinkedIn')
#reg_people = re.compile('">[a-zA-Z0-9._ -]* profiles | LinkedIn')
self.temp = reg_people.findall(self.results)
resul = []
for x in self.temp:
y = string.replace(x, ' | LinkedIn', '')
y = string.replace(y, ' profiles ', '')
y = string.replace(y, 'LinkedIn', '')
y = string.replace(y, '"', '')
y = string.replace(y, '>', '')
if y != " ":
resul.append(y)
return resul
def profiles(self):
reg_people = re.compile('">[a-zA-Z0-9._ -]* - <em>Google Profile</em>')
self.temp = reg_people.findall(self.results)
resul = []
for x in self.temp:
y = string.replace(x, ' <em>Google Profile</em>', '')
y = string.replace(y, '-', '')
y = string.replace(y, '">', '')
if y != " ":
resul.append(y)
return resul
def people_123people(self):
#reg_people = re.compile('www\.123people\.com/s/[a-zA-Z0-9.-_]*\+[a-zA-Z0-9.-_]*\+?[a-zA-Z0-9.-_]*\"')
reg_people = re.compile('www.123people.com/e/[a-zA-Z0-9.-_+]*</cite>')
self.temp = reg_people.findall(self.results)
self.temp2 = []
for x in self.temp:
y = x.replace("www.123people.com/e/", "")
y = y.replace('"', '')
y = y.replace('+', ' ')
y = y.replace('</cite>', '')
self.temp2.append(y)
return self.temp2
def people_jigsaw(self):
res = []
#reg_people = re.compile("'tblrow' title='[a-zA-Z0-9.-]*'><span class='nowrap'/>")
reg_people = re.compile(
"href=javascript:showContact\('[0-9]*'\)>[a-zA-Z0-9., ]*</a></span>")
self.temp = reg_people.findall(self.results)
for x in self.temp:
a = x.split('>')[1].replace("</a", "")
res.append(a)
return res
def hostnames(self):
self.genericClean()
reg_hosts = re.compile('[a-zA-Z0-9.-]*\.' + self.word)
self.temp = reg_hosts.findall(self.results)
hostnames = self.unique()
return hostnames
def set(self):
reg_sets = re.compile('>[a-zA-Z0-9]*</a></font>')
self.temp = reg_sets.findall(self.results)
sets = []
for x in self.temp:
y = string.replace(x, '>', '')
y = string.replace(y, '</a</font', '')
sets.append(y)
return sets
def hostnames_all(self):
reg_hosts = re.compile('<cite>(.*?)</cite>')
temp = reg_hosts.findall(self.results)
for x in temp:
if x.count(':'):
res = x.split(':')[1].split('/')[2]
else:
res = x.split("/")[0]
self.temp.append(res)
hostnames = self.unique()
return hostnames
def unique(self):
self.new = []
for x in self.temp:
if x not in self.new:
self.new.append(x)
return self.new