This repository has been archived by the owner on May 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
CoursePage.py
141 lines (92 loc) · 3.95 KB
/
CoursePage.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
from login import login
from bs4 import BeautifulSoup
def get_courses(reg_no = "", pwd = ""):
br = login(reg_no,pwd)
print br.geturl()
if br.geturl() == ("https://vtop.vit.ac.in/student/home.asp"):
print "SUCCESS"
br.open("https://vtop.vit.ac.in/student/coursepage_view.asp?sem=FS")
response = br.open("https://vtop.vit.ac.in/student/coursepage_view.asp?sem=FS")
soup = BeautifulSoup(response.get_data())
br.select_form("coursepage_view")
#print br.read()
forms = soup.findAll("select")
#print forms[0]
options = forms[0].findAll("option")
options = options[1:]
course= {}
for o in options:
course[o['value']] = o.getText()
return {"status" : "Success_level_1" , "courses" : course}
else :
print "FAIL"
return {"status" : "Failure_level_1"}
#########################################################################################################################################################
def get_slot(reg_no = "", pwd = "", coursekey = ""):
br = login(reg_no,pwd)
print br.geturl()
if br.geturl() == ("https://vtop.vit.ac.in/student/home.asp"):
print "SUCCESS"
br.open("https://vtop.vit.ac.in/student/coursepage_view.asp?sem=FS&crs=%(key)s&slt=&fac=" % {"key" : coursekey})
response = br.open("https://vtop.vit.ac.in/student/coursepage_view.asp?sem=FS&crs=%(key)s&slt=&fac=" % {"key" : coursekey})
soup = BeautifulSoup(response.get_data())
br.select_form("coursepage_view")
#print br.read()
forms = soup.findAll("select")
#print forms[1]
options = forms[1].findAll("option")
options = options[1:]
slot = {}
for o in options:
slot[o['value']] = o.getText()
return {"status" : "Success_level_2" , "slot" : slot}
else :
print "FAIL"
return {"status" : "Failure_level_2"}
#########################################################################################################################################################
def get_faculty(reg_no = "", pwd = "", coursekey = "", slotkey = ""):
br = login(reg_no,pwd)
print br.geturl()
if br.geturl() == ("https://vtop.vit.ac.in/student/home.asp"):
print "SUCCESS"
br.open("https://vtop.vit.ac.in/student/coursepage_view.asp?sem=FS&crs=%(ckey)s&slt=%(skey)s&fac=" % {"ckey" : coursekey, "skey": slotkey})
response = br.open("https://vtop.vit.ac.in/student/coursepage_view.asp?sem=FS&crs=%(key)s&slt=%(skey)s&fac=" % {"key" : coursekey, "skey" : slotkey})
soup = BeautifulSoup(response.get_data())
br.select_form("coursepage_view")
#print br.read()
forms = soup.findAll("select")
#print forms[1]
options = forms[2].findAll("option")
options = options[1:]
slot = {}
for o in options:
slot[o['value']] = o.getText()
return {"status" : "Success_level_2" , "slot" : slot}
else :
print "FAIL"
return {"status" : "Failure_level_2"}
#########################################################################################################################################################
def get_data(reg_no = "", pwd = "", coursekey = "", slotkey = "", fackey = ""):
br = login(reg_no,pwd)
print br.geturl()
if br.geturl() == ("https://vtop.vit.ac.in/student/home.asp"):
print "SUCCESS"
def select_form(form):
return form.attrs.get('action', None) == 'coursepage_view3.asp'
br.open("https://vtop.vit.ac.in/student/coursepage_view.asp?sem=FS&crs=%(ckey)s&slt=%(skey)s&fac=%(fkey)s" % {"ckey" : coursekey, "skey": slotkey, "fkey" : fackey})
response = br.open("https://vtop.vit.ac.in/student/coursepage_view.asp?sem=FS&crs=%(key)s&slt=%(skey)s&fac=%(fkey)s" % {"key" : coursekey, "skey" : slotkey, "fkey" : fackey})
soup = BeautifulSoup(response.get_data())
#form = soup.find("form",)
br.select_form(predicate = select_form)
res = br.submit()
print br.geturl()
soup = BeautifulSoup(res.get_data())
#extracting data
links = soup.findAll('a')
href = []
for l in links:
href.append(l['href'])
return {"status" : "Success_finally" , "uploads" : href}
else :
print "FAIL"
return {"status" : "Failure_end"}