-
Notifications
You must be signed in to change notification settings - Fork 0
/
web_scrapper.py
339 lines (260 loc) · 12.8 KB
/
web_scrapper.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
"""
Web Scrapper made by : Naman Garg
Section : CS A 04
Roll Number : 12112061
Contact: <[email protected]>
NIT Scrapped in this project are:
1. NIT Uttarakhand
2. NIT Puducherry
3. NIT Arunachal Pradesh
4. NIT Sikkim
5. NIT Delhi
6. NIT Mizoram
7. NIT Nagaland
8. NIT Andhra Pradesh
"""
from selenium import webdriver
from bs4 import BeautifulSoup
from selenium.webdriver.firefox.options import Options
import docx
doc = docx.Document()
options = Options()
options.add_argument("--headless")
driver = webdriver.Firefox(options=options)
#============================================================================================= 1. NIT Uttarakhand =============================================================================================
doc.add_heading("1. NIT Uttarakhand", 0)
doc.add_paragraph("Full Name \n Designation \n Email ID \n Contact Number \n Research area")
url_list = ['https://nituk.ac.in/computer-science-engineering/peoples', 'https://nituk.ac.in/civil-engineering/peoples',
'https://nituk.ac.in/electrical-engineering/peoples', 'https://nituk.ac.in/electronics-engineering/peoples',
'https://nituk.ac.in/mechanical-engineering/peoples'
]
for page in url_list:
driver.get(page)
soup = BeautifulSoup(driver.page_source, "html.parser")
s = soup.find_all("td")
for faculty in s:
facultyData = faculty.text
# Skip, because not all td are faculty
if facultyData.find("Designation") == -1:
continue
facultyData = facultyData.strip().split("\n")
# Faculty Name
fac_name = facultyData[0].strip()
# Designation
fac_designation = facultyData[2].split(":")[1]
# Email ID
if len(facultyData) >= 5:
fac_email = facultyData[4].split(":")[1].strip()
else:
fac_email = "-"
fac_phone = "-"
# Phone Number
if len(facultyData) >= 4:
for string in facultyData[3].split():
if string.isnumeric():
fac_phone = string
break
fac_research = "-"
if len(facultyData) >= 6:
fac_research = facultyData[5].split(":")[1].strip()
doc.add_paragraph("\n==============================================================\n" +
fac_name + " \n" + fac_designation + " \n " + fac_email + " \n " +
fac_phone + " \n " + fac_research)
doc.add_page_break()
doc.save('output.docx')
print("Done NIT Uttarakhand")
# ============================================================================================= 2. NIT Puducherry =============================================================================================
doc.add_heading("2. NIT Puducherry", 0)
doc.add_paragraph("Full Name \n Designation \n Email ID \n Contact Number \n Research area")
url_list = ["https://nitpy.ac.in/academics/departments/civil/faculty",
"https://nitpy.ac.in/academics/departments/cse/faculty",
"https://nitpy.ac.in/academics/departments/ece/faculty",
"https://nitpy.ac.in/academics/departments/eee/faculty",
"https://nitpy.ac.in/academics/departments/mech/faculty"
]
for page in url_list:
driver.get(page)
driver.refresh()
soup = BeautifulSoup(driver.page_source, "html.parser")
s = soup.find_all("app-department-faculty-view")
for faculty in s:
facultyData = faculty.find_all("p")
# Faculty Name
fac_name = facultyData[0].text.split(":")[1].strip()
# Designation
fac_designation = facultyData[1].text.split(":")[1].strip()
# E-Mail
fac_email = facultyData[2].text.split(":")[1].strip()
# Phone Number
fac_phone = facultyData[3].text.split(":")[1].strip()
fac_research = "-"
if len(facultyData) >= 5:
try:
fac_research = facultyData[4].text.split(":")[1].strip()
except:
fac_research = "-"
finally:
pass
doc.add_paragraph("\n==============================================================\n" +
fac_name + " \n" + fac_designation + " \n " + fac_email + " \n " +
fac_phone + " \n " + fac_research)
doc.save('output.docx')
doc.add_page_break()
print("Done NIT Puducherry")
# ============================================================================================= 3. NIT Arunachal Pradesh =============================================================================================
doc.add_heading("3. NIT Arunachal Pradesh", 0)
doc.add_paragraph("Full Name \n Designation \n Email ID \n Contact Number \n Research area")
url_list = ["https://www.nitap.ac.in/department/faculty?faculty=33b1f5929e",
"https://www.nitap.ac.in/department/faculty?faculty=1dbf504017",
"https://www.nitap.ac.in/department/faculty?faculty=8345cde791",
"https://www.nitap.ac.in/department/faculty?faculty=66badff20c",
"https://www.nitap.ac.in/department/faculty?faculty=cad3da575a",
"https://www.nitap.ac.in/department/faculty?faculty=89f0915482"
]
for page in url_list:
driver.get(page)
soup = BeautifulSoup(driver.page_source, "html.parser")
s = soup.find_all("div", class_="gdlr-core-personnel-list-content-wrap")
for faculty in s:
# Faculty Name
fac_name = faculty.find_all("h3")[0].text.strip()
# Designation
fac_designation = faculty.find_all("div", class_="gdlr-core-personnel-list-position gdlr-core-info-font gdlr-core-skin-caption")[0].text.strip()
# E-Mail
fac_email = faculty.find_all("a")[0].text.strip()
# Phone Number
fac_phone = faculty.find_all("div", class_="kingster-personnel-info-list kingster-type-phone")[0].text.strip()
# Research Area
fac_research = faculty.find_all("p")[-1].text.strip()
doc.add_paragraph("\n==============================================================\n" +
fac_name + " \n" + fac_designation + " \n " + fac_email + " \n " +
fac_phone + " \n " + fac_research)
doc.save('output.docx')
doc.add_page_break()
print("Done NIT Arunachal Pradesh")
# ============================================================================================= 4. NIT Sikkim =============================================================================================
doc.add_heading("4. NIT Sikkim", 0)
doc.add_paragraph("Full Name \n Designation \n Email ID \n Contact Number \n Research area")
url_list = ["https://cse.nitsikkim.ac.in/people.php",
"https://ece.nitsikkim.ac.in/people.php",
"https://eee.nitsikkim.ac.in/people.php",
"https://me.nitsikkim.ac.in/people.php",
"https://ce.nitsikkim.ac.in/people.php",
]
for page in url_list:
driver.get(page)
soup = BeautifulSoup(driver.page_source, "html.parser")
s = soup.find_all("div", class_="card-body")
for faculty in s:
# Faculty Name
fac_name = faculty.find_all("h5")[0].text.strip()
# Designation
fac_designation = faculty.find_all("h6")[0].text.strip()
# E-Mail
fac_email = faculty.find_all("p", class_="card-text")[0].text.split("+")[0].strip()
# # Phone Number
fac_phone = "+" + faculty.find_all("p", class_="card-text")[0].text.split("+")[-1].strip()
# Research Area
fac_research = faculty.find_all("p", class_="card-text")[-1].text.strip()
doc.add_paragraph("\n==============================================================\n" +
fac_name + " \n" + fac_designation + " \n " + fac_email + " \n " +
fac_phone + " \n " + fac_research)
doc.save('output.docx')
doc.add_page_break()
print("Done NIT Sikkim")
# ============================================================================================= 5. NIT Delhi =============================================================================================
doc.add_heading("5. NIT Delhi", 0)
doc.add_paragraph("Full Name \n Designation \n Email ID \n Contact Number \n Research area")
url_list = ["https://nitdelhi.ac.in/?page_id=11979",
"https://nitdelhi.ac.in/?page_id=11977",
"https://nitdelhi.ac.in/?page_id=11985",
"https://nitdelhi.ac.in/?page_id=11981",
"https://nitdelhi.ac.in/?page_id=11993"
]
for page in url_list:
driver.get(page)
soup = BeautifulSoup(driver.page_source, "html.parser")
s = soup.find_all("tr")
for faculty in s:
if len(faculty.find_all("a")) == 0:
continue
doc.add_paragraph("\n==============================================================\n" +
faculty.find_all("td")[1].text)
doc.save('output.docx')
doc.add_page_break()
print("Done NIT Delhi")
#============================================================================================= 6. NIT Mizoram =============================================================================================
doc.add_heading("6. NIT Mizoram", 0)
doc.add_paragraph("Full Name \n Designation \n Email ID \n Contact Number \n Research area")
url_list = ["https://www.nitmz.ac.in/Department_FaculyList.aspx?nDeptID=cg",
"https://www.nitmz.ac.in/Department_FaculyList.aspx?nDeptID=ec",
"https://www.nitmz.ac.in/Department_FaculyList.aspx?nDeptID=ck",
"https://www.nitmz.ac.in/Department_FaculyList.aspx?nDeptID=ci",
"https://www.nitmz.ac.in/Department_FaculyList.aspx?nDeptID=cm"
]
for page in url_list:
driver.get(page)
soup = BeautifulSoup(driver.page_source, "html.parser")
s = soup.find_all("table", class_="DataGrid")[0].find_all("tr")
for faculty in s:
if len(faculty.find_all("a")) == 0:
continue
# Faculty Name
fac_name = faculty.find_all("a")[0].text.strip()
# Designation
fac_designation = faculty.find_all("td")[1].text.strip()
# E-Mail
fac_email = faculty.find_all("td")[2].text.strip()
doc.add_paragraph("\n==============================================================\n" +
fac_name + " \n" + fac_designation + " \n " + fac_email + " \n " +
"-" + " \n " + "-")
doc.save('output.docx')
doc.add_page_break()
print("Done NIT Mizoram")
#============================================================================================= 7. NIT Nagaland =============================================================================================
doc.add_heading("7. NIT Nagaland", 0)
doc.add_paragraph("Full Name \n Designation \n Email ID \n Contact Number \n Research area")
url_list = ["https://www.nitnagaland.ac.in/index.php/cse-people/cse-faculty",
"https://www.nitnagaland.ac.in/index.php/eee-people/eee-faculty",
"https://www.nitnagaland.ac.in/index.php/ece-people/ece-faculty",
"https://www.nitnagaland.ac.in/index.php/eie-people/eie-faculty",
]
for page in url_list:
driver.get(page)
soup = BeautifulSoup(driver.page_source, "html.parser")
s = soup.find_all("div", class_="fp-testimonials")
for faculty in s:
if len(faculty.find_all("b")) <= 1:
continue
# Faculty Name
fac_name = faculty.find_all("b")[0].text.strip()
# Designation
fac_designation = faculty.find_all("b")[1].text.strip()
# E-Mail
fac_email = faculty.text.split("\n")[5].strip()
# Research Area
fac_research = faculty.text.split("\n")[6].strip()
doc.add_paragraph("\n==============================================================\n" +
fac_name + " \n" + fac_designation + " \n " + fac_email + " \n " +
"-" + " \n " + fac_research)
doc.save('output.docx')
doc.add_page_break()
print("Done NIT Nagaland")
# ============================================================================================= 8. NIT Andhra Pradesh =============================================================================================
doc.add_heading("8. NIT Andhra Pradesh", 0)
doc.add_paragraph("Full Name \n Designation \n Email ID \n Contact Number \n Research area")
url_list = ["https://nitandhra.ac.in/main/fm",
]
for page in url_list:
driver.get(page)
soup = BeautifulSoup(driver.page_source, "html.parser")
s = soup.find_all("div", class_="panel-body")
for faculty in s:
if len(faculty.find_all("font")) != 1:
continue
fac_data = faculty.text.strip().split("Contact:")
doc.add_paragraph("\n==============================================================\n" +
fac_data[0] + " \n " + fac_data[1])
doc.save('output.docx')
print("Done NIT Andhra Pradesh")
print("\n\nDone Scrapping.\nThank You")