-
Notifications
You must be signed in to change notification settings - Fork 5
/
scraping.py
283 lines (278 loc) · 9.15 KB
/
scraping.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
from bs4 import BeautifulSoup
import requests
import MySQLdb
conn = MySQLdb.connect("localhost","root","justgoogleit","results" )
cursor = conn.cursor()
arr = [17,13,9,5]
def push_students(rollno,name,cgpi):
try:
cursor.execute('''UPDATE students SET cgpi=%s where roll_no=%s''',(cgpi, rollno))
# cursor.execute('''INSERT into students (roll_no,name,cgpi) values (%s,%s,%s)''',(rollno,name,cgpi))
conn.commit()
except:
print conn.rollback()
print ("MKK")
def push_semester(rollno,semester,sgpi,cgpi):
try:
cursor.execute('''INSERT into semesters (roll_no,sgpi,cgpi,semester_no) values (%s,%s,%s,%s)''',(rollno,sgpi,cgpi,semester))
conn.commit()
except:
print conn.rollback()
def push_subjects(id1,rollno,semester,subname,obtainCR,totalCR):
try:
cursor.execute('''INSERT into subjects (id,roll_no,semester_no,subject_name,obtainCR,TotalCR) values (%s,%s,%s,%s,%s,%s)''',(id1,rollno,semester,subname,obtainCR,totalCR))
conn.commit()
except:
print conn.rollback()
def btech():
roll_2="1"
for year in range(4):
roll_2 = roll_2+str(year+3)
print "Year"+roll_2
roll2 = roll_2
for branch in range(7):
roll_2 = roll_2 + str(branch+1)
print "Branch"+roll_2
roll3 = roll_2
for roll_no in range(99):
if roll_no<9:
roll_2 = roll_2 + "0" + str(roll_no+1)
else:
roll_2 = roll_2 + str(roll_no+1)
print roll_2 + " Site "+ roll2
form_data={
'RollNumber' : roll_2
}
url = "http://14.139.56.15/scheme"+str(roll2)+"/studentresult/details.asp"
response = requests.post(url, data = form_data)
page=BeautifulSoup(response.text)
#print page.prettify()
table=page.find_all('table', class_='ewTable')
roll="1"+str(year+3)
if len(table)<arr[year+1]:
roll_2 = roll3
continue
tr=table[arr[year+1]-1].find_all('tr')
td=tr[1].find_all('td', class_='auto-style5')
nametr=table[0].find_all('tr')
nametd=nametr[0].find_all('td', class_='auto-style5')
print (nametd[1].text).strip()
x = (td[2].text)
print x[x.find("=")+1:]
push_students(roll_2,(nametd[1].text).strip(),x[x.find("=")+1:])
print "Name: "+ (nametd[1].text).strip()+" SGPI: "+ x[x.find("=")+1:]
for k in range(arr[year+1]/2):
tables = page.find_all('table',class_='ewTable')
trs = tables[k*2+2].find_all('tr')
tds = trs[1].find_all('td',class_='auto-style5')
x1 = (tds[0].text)
y1 = (tds[2].text)
print x1
print y1
push_semester(roll_2,roll_2+str(k+1),x1[x1.find("=")+1:],y1[y1.find("=")+1:])
trs2 = tables[k*2+1].find_all('tr')
#print trs2
subjectnum = len(trs2)
#print type(subjectnum)
#print subjectnum
#print "MKKKKK"
for l in range(subjectnum-1):
tds2 = trs2[1+l].find_all('td',class_='auto-style5')
subname = (tds2[1].text).strip()
#subptr = int(tds2[5].text)/
push_subjects(roll_2+str(k+1)+tds2[0].text,roll_2,roll_2+str(k+1),subname,tds2[5].text,str(10*int(tds2[3].text)))
roll_2 = roll3
roll_2 = roll2
roll_2 = "1"
def dual():
roll_2="1"
site = "1"
for year in range(2):
roll_2 = roll_2+str(year+4)+"MI"
site = site+str(year+4)
print "Year"+roll_2
roll2 = roll_2
for branch in range(2):
roll_2 = roll_2 + str(branch+4)
roll3 = roll_2
print "Branch"+roll3
for roll_no in range(60):
if roll_no<9:
roll_2 = roll_2 + "0" + str(roll_no+1)
else:
roll_2 = roll_2 + str(roll_no+1)
print roll_2 + " Site "+site
form_data={
'RollNumber' : roll_2
}
url = "http://14.139.56.15/scheme"+str(site)+"/studentresult/details.asp"
response = requests.post(url, data = form_data)
page=BeautifulSoup(response.text)
#print page.prettify()
table=page.find_all('table', class_='ewTable')
roll="1"+str(year+3)
#print "Table Length: "+ str(len(table))
if len(table)<arr[year+2]:
roll_2 = roll3
continue
tr=table[arr[year+2]-1].find_all('tr')
td=tr[1].find_all('td', class_='auto-style5')
nametr=table[0].find_all('tr')
nametd=nametr[0].find_all('td', class_='auto-style5')
print (nametd[1].text).strip()
x = (td[2].text)
print x[x.find("=")+2:]
push_students(roll_2,(nametd[1].text).strip(),x[x.find("=")+1:])
print "Name: "+ (nametd[1].text).strip()+" SGPI: "+ x[x.find("=")+1:]
for k in range(arr[year+2]/2):
tables = page.find_all('table',class_='ewTable')
trs = tables[k*2+2].find_all('tr')
tds = trs[1].find_all('td',class_='auto-style5')
x1 = (tds[0].text)
y1 = (tds[2].text)
print x1
print y1
push_semester(roll_2,roll_2+str(k+1),x1[x1.find("=")+1:],y1[y1.find("=")+1:])
trs2 = tables[k*2+1].find_all('tr')
#print trs2
subjectnum = len(trs2)
#print type(subjectnum)
#print subjectnum
#print "MKKKKK"
for l in range(subjectnum-1):
tds2 = trs2[1+l].find_all('td',class_='auto-style5')
subname = (tds2[1].text).strip()
#subptr = int(tds2[5].text)/
push_subjects(roll_2+str(k+1)+tds2[0].text,roll_2,roll_2+str(k+1),subname,tds2[5].text,str(10*int(tds2[3].text)))
roll_2 = roll3
roll_2 = roll2
roll_2 = "1"
site = "1"
def iiit():
roll_2="IIITU1"
site = "iiituna1"
for year in range(2):
roll_2 = roll_2+str(year+4)
site = site+str(year+4)
print "Year"+roll_2
roll2 = roll_2
for branch in range(2):
roll_2 = roll_2 + str(branch+1)
print "Branch"+roll_2
roll3 = roll_2
print "ROll3 " +roll3;
for roll_no in range(30):
if roll_no<9:
roll_2 = roll_2 + "0" + str(roll_no+1)
else:
roll_2 = roll_2 + str(roll_no+1)
print roll_2
form_data={
'RollNumber' : roll_2
}
url = "http://14.139.56.15/"+str(site)+"/studentresult/details.asp"
response = requests.post(url, data = form_data)
page=BeautifulSoup(response.text)
table=page.find_all('table', class_='ewTable')
roll="IIITU1"+str(year+4)
if len(table)<arr[year+2]:
roll_2 = roll3
continue
tr=table[arr[year+2]-1].find_all('tr')
td=tr[1].find_all('td', class_='ewTableAltRow')
nametr=table[0].find_all('tr')
nametd=nametr[0].find_all('td', class_='ewTableAltRow')
print (nametd[0].text).strip()
x = (td[2].text)
print "Name: "+ (nametd[0].text).strip()+" SGPI: "+ x[x.find("=")+1:]
push_students(roll_2,(nametd[0].text).strip(),x[x.find("=")+1:])
for k in range(arr[year+2]/2):
tables = page.find_all('table',class_='ewTable')
trs = tables[k*2+2].find_all('tr')
tds = trs[1].find_all('td',class_='ewTableAltRow')
x1 = (tds[0].text)
y1 = (tds[2].text)
print x1
print y1
push_semester(roll_2,roll_2+str(k+1),x1[x1.find("=")+1:],y1[y1.find("=")+1:])
trs2 = tables[k*2+1].find_all('tr')
#print trs2
subjectnum = len(trs2)
#print type(subjectnum)
#print subjectnum
#print "MKKKKK"
for l in range(subjectnum-1):
tds2 = trs2[1+l].find_all('td',class_='ewTableAltRow')
subname = (tds2[1].text).strip()
#subptr = int(tds2[5].text)/
push_subjects(roll_2+str(k+1)+tds2[0].text,roll_2,roll_2+str(k+1),subname,tds2[5].text,str(10*int(tds2[3].text)))
roll_2 = roll3
roll_2 = roll2
roll_2 = "IIITU1"
site = "iiituna1"
def mtech():
roll_2="1"
site = "1"
for year in range(2):
roll_2 = roll_2+str(year+4)+"M"
site = site+str(year+4)
print "Year"+roll_2
roll2 = roll_2
for branch in range(7):
roll_2 = roll_2 + str(branch+6)
roll3 = roll_2
print "Branch"+roll3
for roll_no in range(60):
if roll_no<9:
roll_2 = roll_2 + "0" + str(roll_no+1)
else:
roll_2 = roll_2 + str(roll_no+1)
print roll_2 + " Site "+site
form_data={
'RollNumber' : roll_2
}
url = "http://14.139.56.15/mtech"+str(site)+"/studentresult/details.asp"
response = requests.post(url, data = form_data)
page=BeautifulSoup(response.text)
#print page.prettify()
table=page.find_all('table', class_='ewTable')
roll="IIITU1"+str(year+5)
if len(table)<arr[year+3]:
roll_2 = roll3
continue
tr=table[arr[year+3]-1].find_all('tr')
td=tr[1].find_all('td', class_='ewTableAltRow')
nametr=table[0].find_all('tr')
nametd=nametr[0].find_all('td', class_='ewTableAltRow')
print (nametd[0].text).strip()
x = (td[2].text)
print "Name: "+ (nametd[0].text).strip()+" SGPI: "+ x[x.find("=")+1:]
push_students(roll_2,(nametd[0].text).strip(),x[x.find("=")+1:])
for k in range(arr[year+3]/2):
tables = page.find_all('table',class_='ewTable')
trs = tables[k*2+2].find_all('tr')
tds = trs[1].find_all('td',class_='ewTableAltRow')
x1 = (tds[0].text)
y1 = (tds[2].text)
print x1
print y1
push_semester(roll_2,roll_2+str(k+1),x1[x1.find("=")+1:],y1[y1.find("=")+1:])
trs2 = tables[k*2+1].find_all('tr')
#print trs2
subjectnum = len(trs2)
#print type(subjectnum)
#print subjectnum
#print "MKKKKK"
for l in range(subjectnum-1):
tds2 = trs2[1+l].find_all('td',class_='ewTableAltRow')
subname = (tds2[1].text).strip()
#subptr = int(tds2[5].text)/
push_subjects(roll_2+str(k+1)+tds2[0].text,roll_2,roll_2+str(k+1),subname,tds2[5].text,str(10*int(tds2[3].text)))
roll_2 = roll3
roll_2 = roll2
roll_2 = "1"
site = "1"
btech()
dual()
iiit()
mtech()