-
Notifications
You must be signed in to change notification settings - Fork 0
/
exam_schedule.py
46 lines (42 loc) · 1.28 KB
/
exam_schedule.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
import json
import warnings
from bs4 import BeautifulSoup
import index
warnings.filterwarnings('ignore', 'Unverified HTTPS request')
url = "https://vtop.vit.ac.in/vtop/examinations/doSearchExamScheduleForStudent"
data = {
"authorizedID": index.username,
"semesterSubId": index.semester
}
req = index.unified_session.post(url, data=data, headers=index.headers, verify=False)
soup = BeautifulSoup(req.content, 'html.parser')
table = soup.find_all('table', {"class": "customTable"})[0]
headings = (table.find('tr')).find_all('td')
trs = table.find_all('tr')
trs = trs[1:]
i = 0
exam = {}
while i < len(trs):
tds = trs[i].find_all('td')
if len(tds) == 1:
exam_type = tds[0].text
each_exam = []
i = i + 1
tds = trs[i].find_all('td')
while len(tds) > 1:
each_sub = {}
for j in range(0, len(tds)):
each_sub[headings[j].text] = tds[j].text
each_exam.append(each_sub)
i = i + 1
if i < len(trs):
tds = trs[i].find_all('td')
else:
break
exam[exam_type] = each_exam
else:
i = i + 1
exam = json.dumps(exam)
exam = json.loads(exam)
with open('exam_schedule.json', 'w') as outfile:
json.dump(exam, outfile, indent=4)