-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolleges_web_scrap_main.py
226 lines (207 loc) · 10.6 KB
/
colleges_web_scrap_main.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
import requests
import bs4
def alphabetical_order(college_details):
list = college_details.keys()
list = sorted(list)
for i in list:
print("\n================================================")
print("College Name :" ,i)
print("Tution Cost in Range($-$$$$) :", college_details[i][0])
print("Avg Retention Rate :", college_details[i][1])
print("Programs Available :", college_details[i][2])
print("Student Faculity Ration :", college_details[i][3])
print("Facilities in College :", college_details[i][4])
print("Placement Services :", college_details[i][5])
print("On Campus Housing :", college_details[i][6])
print("================================================\n")
def plaments_services(college_details):
for i in college_details:
if college_details[i][5]=='Yes':
print("\n================================================")
print("College Name :" ,i)
print("Tution Cost in Range($-$$$$) :", college_details[i][0])
print("Avg Retention Rate :", college_details[i][1])
print("Programs Available :", college_details[i][2])
print("Student Faculity Ration :", college_details[i][3])
print("Facilities in College :", college_details[i][4])
print("Placement Services :", college_details[i][5])
print("On Campus Housing :", college_details[i][6])
print("================================================\n")
def based_on_student_faculity_ratio(college_details):
list = []
for i in college_details:
list.append(college_details[i][3])
list = sorted(list)
list = list[::-1]
temp = []
for r in list:
for i in college_details:
if college_details[i][3]==r and i not in temp:
temp.append(i)
print("\n================================================")
print("College Name :" ,i)
print("Tution Cost in Range($-$$$$) :", college_details[i][0])
print("Avg Retention Rate :", college_details[i][1])
print("Programs Available :", college_details[i][2])
print("Student Faculity Ration :", college_details[i][3])
print("Facilities in College :", college_details[i][4])
print("Placement Services :", college_details[i][5])
print("On Campus Housing :", college_details[i][6])
print("================================================\n")
def tution_cost_range(college_details):
for r in range(1,5):
for i in college_details:
if len(college_details[i][0])==r:
print("\n================================================")
print("College Name :" ,i)
print("Tution Cost in Range($-$$$$) :", college_details[i][0])
print("Avg Retention Rate :", college_details[i][1])
print("Programs Available :", college_details[i][2])
print("Student Faculity Ration :", college_details[i][3])
print("Facilities in College :", college_details[i][4])
print("Placement Services :", college_details[i][5])
print("On Campus Housing :", college_details[i][6])
print("================================================\n")
def avg_retention_ratios(college_details):
list = []
for i in college_details:
list.append(float(college_details[i][1]))
list = sorted(list)
list = list[::-1]
temp = []
for r in list:
for i in college_details:
if float(college_details[i][1])==r and i not in temp:
temp.append(i)
print("\n================================================")
print("College Name :" ,i)
print("Tution Cost in Range($-$$$$) :", college_details[i][0])
print("Avg Retention Rate :", college_details[i][1])
print("Programs Available :", college_details[i][2])
print("Student Faculity Ration :", college_details[i][3])
print("Facilities in College :", college_details[i][4])
print("Placement Services :", college_details[i][5])
print("On Campus Housing :", college_details[i][6])
print("================================================\n")
def colleges(college_details):
for i in college_details:
print("\n================================================")
print("College Name :" ,i)
print("Tution Cost in Range($-$$$$) :", college_details[i][0])
print("Avg Retention Rate :", college_details[i][1])
print("Programs Available :", college_details[i][2])
print("Student Faculity Ration :", college_details[i][3])
print("Facilities in College :", college_details[i][4])
print("Placement Services :", college_details[i][5])
print("On Campus Housing :", college_details[i][6])
print("================================================\n")
def main():
print("\n========= Welcome To WebScraping of indiaeducation.net site ========\n")
res = requests.get("http://www.indiaeducation.net/studyabroad/listing/")
soup = bs4.BeautifulSoup(res.content,'html.parser')
college_details = {}
college_name_tag = soup.find_all('div', attrs={'class': 'college_div'})
for i in college_name_tag:
college_name = i.find('span', class_= 'college_name2')
college_name = (college_name.text).strip()
college_details[college_name]=[]
tution_range = i.find(class_='tuition_cost')
tution_range = tution_range.find('font', class_='bluefont')
tution_range=tution_range.text
college_details[college_name].append(tution_range)
avg_retention_rate = i.find(class_="distance_edu_value")
avg_retention_rate=avg_retention_rate.text
college_details[college_name].append(avg_retention_rate)
programs_avail = i.find(class_="percent_transfer_value")
programs_avail=programs_avail.text
college_details[college_name].append(programs_avail)
student_faculity_ratio = i.find(class_="sa_studentToFacultyRatio")
student_faculity_ratio = student_faculity_ratio.find('span',class_="bluefont")
student_faculity_ratio = student_faculity_ratio.text
college_details[college_name].append(student_faculity_ratio)
features = i.find(class_="listing_sa_ss_text_sizesetting")
if features:
features = features.text
college_details[college_name].append(features)
else:
college_details[college_name].append("None")
placements = i.find(class_='sa_placementServices')
if placements:
placements= placements.find('span',class_="bluefont")
placements = placements.text
college_details[college_name].append(placements)
else:
college_details[college_name].append("No")
on_campus_housing = i.find(class_='sa_onCampusHousing')
if on_campus_housing:
on_campus_housing = on_campus_housing.find('span',class_="bluefont")
on_campus_housing = on_campus_housing.text
college_details[college_name].append(on_campus_housing)
else:
college_details[college_name].append("No")
count = 0;
while True:
print("Sort Colleges Based on Options:")
print("===============================")
print("\n 1. Top 20 colleges \n 2. Colleges in Alphabetical order \n 3. Colleges Based on Student to Faculity Ratio \n 4. Colleges Based on Avg Retention Ration \n 5. Colleges Based on Tution Cost Range (\"$\"(Low)-\"$$$$\"(High) \n 6. Colleges Based on Placement Services\n 7. Exit")
print("\n================================================\n")
option = input("Enter Option from 1 to 7 : ")
if option=="1":
colleges(college_details)
count=0
print("If you Wish To Close Enter Y/y or Press any key")
options = input()
if options =='Y' or options =='y':
print("============== Thank You ============")
exit()
elif option=="2":
alphabetical_order(college_details);
count=0
print("If you Wish To Close Enter Y/y or Press any key")
options = input()
if options =='Y' or options =='y':
print("============== Thank You ============")
exit()
elif option=="3":
based_on_student_faculity_ratio(college_details);
count=0
print("If you Wish To Close Enter Y/y or Press any key")
options = input()
if options =='Y' or options =='y':
print("============== Thank You ============")
exit()
elif option=="4":
avg_retention_ratios(college_details);
count=0
print("If you Wish To Close Enter Y/y or Press any key")
options = input()
if options =='Y' or options =='y':
print("============== Thank You ============")
exit()
elif option=="5":
tution_cost_range(college_details)
count=0
print("If you Wish To Close Enter Y/y or Press any key")
options = input()
if options =='Y' or options =='y':
print("============== Thank You ============")
exit()
elif option=="6":
plaments_services(college_details);
count=0
print("If you Wish To Close Enter Y/y or Press any key")
options = input()
if options =='Y' or options =='y':
print("============== Thank You ============")
exit()
elif option=="7":
print("============== Thank You ============")
exit()
else:
count = count+1;
if count == 3:
print("\n======You have Entered Wrong Option Multiple Times Please Try Again======\n")
exit()
print("Please Enter Numeric value Between 1-7\n\n You have %d Chances to Choose Correct Option\n" %(3-count))
if __name__ == "__main__":
main()