-
Notifications
You must be signed in to change notification settings - Fork 22
/
Bing_Scraper.py
executable file
·137 lines (124 loc) · 4.33 KB
/
Bing_Scraper.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
#!/usr/bin/env python
from bs4 import BeautifulSoup
import sys
import mechanize
print "\n*************************************************"
print "** Bing Scrape Email Harvester **"
print "** by Pan0pt1c0n (Justin Hutchens) **"
print "** ...GONE PHISHING!!! **"
print "*************************************************\n\n"
if len(sys.argv) != 4:
print "Usage - ./Bing_Scraper.py [Format num] [suffix] [output_file]"
print "\nFORMATS:"
print "1 - [first].[last]@[suffix]"
print "2 - [first][last]@[suffix]"
print "3 - [first initial][last]@[suffix]"
print "4 - [first]_[last]@[suffix]\n"
print "Example - ./Bing_Scraper.py 1 company.com output.txt"
print "Example will create email list in the form of john.smith@company.com\n\n"
sys.exit()
format = int(sys.argv[1])
suffix = str(sys.argv[2]).lower()
filename = str(sys.argv[3])
file = open(filename,'w')
def format_1(names,suffix):
emails = []
for x in names:
try:
first = x.split(' ')[0].lower()
last = x.split(' ')[1].lower()
emails.append(first + '.' + last + '@' + suffix)
except:
pass
return emails
def format_2(names,suffix):
emails = []
for x in names:
try:
first = x.split(' ')[0].lower()
last = x.split(' ')[1].lower()
emails.append(first + last + '@' + suffix)
except:
pass
return emails
def format_3(names,suffix):
emails = []
for x in names:
try:
first = x.split(' ')[0].lower()
last = x.split(' ')[1].lower()
emails.append(first[0] + last + '@' + suffix)
except:
pass
return emails
def format_4(names,suffix):
emails = []
for x in names:
try:
first = x.split(' ')[0].lower()
last = x.split(' ')[1].lower()
emails.append(first + '_' + last + '@' + suffix)
except:
pass
return emails
## Get Company Name & URL encode
company = raw_input("Enter the company name: ")
company = company.replace(' ','%20')
## Gather number of entries with mechanize
br = mechanize.Browser()
br.set_handle_robots(False)
response = br.open('http://www.bing.com/search?q=(site%3A%22www.linkedin.com%2Fin%2F%22%20OR%20site%3A%22www.linkedin.com%2Fpub%2F%22)%20%26%26%20(NOT%20site%3A%22www.linkedin.com%2Fpub%2Fdir%2F%22)%20%26%26%20%22'+company+'%22&qs=n&form=QBRE&pq=(site%3A%22www.linkedin.com%2Fin%2F%22%20or%20site%3A%22www.linkedin.com%2Fpub%2F%22)%20%26%26%20(not%20site%3A%22www.linkedin.com%2Fpub%2Fdir%2F%22)%20%26%26%20%22'+company+'%22').read()
soup = BeautifulSoup(response)
link_list = []
for link in br.links():
link_list.append(link.text)
if "Next" in link_list:
more_records = True
else:
more_records = False
## Set Query Record Incrementation & Initialize Loop
names = []
for definition in soup.findAll('h2'):
definition = definition.renderContents()
if "LinkedIn" in definition:
names.append((((((definition.replace('<strong>','')).replace('</strong>','')).split('>')[1]).split('|')[0]).rstrip()).split(',')[0])
if format == 1:
emails = format_1(names,suffix)
elif format == 2:
emails = format_2(names,suffix)
elif format == 3:
emails = format_3(names,suffix)
elif format == 4:
emails = format_4(names,suffix)
else:
print "\n\n[-] ERROR: Improper Format Value Supplied\n"
sys.exit()
for x in emails:
print x
file.write(x+"\n")
while more_records == True:
response = br.follow_link(text="Next")
names = []
soup = BeautifulSoup(response)
for definition in soup.findAll('h2'):
definition = definition.renderContents()
if "LinkedIn" in definition:
names.append((((((definition.replace('<strong>','')).replace('</strong>','')).split('>')[1]).split('|')[0]).rstrip()).split(',')[0])
if format == 1:
emails = format_1(names,suffix)
elif format == 2:
emails = format_2(names,suffix)
elif format == 3:
emails = format_3(names,suffix)
elif format == 4:
emails = format_4(names,suffix)
for x in emails:
print x
file.write(x+"\n")
link_list = []
for link in br.links():
link_list.append(link.text)
if "Next" in link_list:
more_records = True
else:
more_records = False