Skip to content

Commit ba76b55

Browse files
committed
Semester Overview Table is now parsed correctly
1 parent 6efacb4 commit ba76b55

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

campusnet.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121
response = requests.post('https://dualis.dhbw.de/scripts/mgrqispi.dll', headers=headers, data=data)
2222

2323
cnsc = response.headers['Set-cookie'][0:38].replace(" ", "") #cookie in format "csnc =FA27B61020C03AA5A83046B13D6CC38D; HttpOnly; secure" broken down to "csnc=FA27B61020C03AA5A83046B13D6CC38D"
24-
2524
# TODO: something is borken with that cnsc. It looks identical to a valid one, but only gives access denied.
26-
# debug:
2725
cnsc = 'cnsc=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
2826

27+
# TODO get -N Arguments from response redirect?
28+
2929
## Get all Semesters
3030

3131
# Prüfungsergebnisse Tab: https://dualis.dhbw.de/scripts/mgrqispi.dll?APPNAME=CampusNet&PRGNAME=COURSERESULTS&ARGUMENTS=-N422875220398735,-N000307,
32+
# die arguments sind wohl dynamisch...
3233
# Semesterlist: <select id="semester" .*> </select>
3334
# then get value from option, display name
3435

@@ -37,7 +38,7 @@
3738
'Cookie': cnsc,
3839
}
3940

40-
response = requests.get('https://dualis.dhbw.de/scripts/mgrqispi.dll?APPNAME=CampusNet&PRGNAME=COURSERESULTS&ARGUMENTS=-N591469968597102,-N000307', data="", headers=headers)
41+
response = requests.get('https://dualis.dhbw.de/scripts/mgrqispi.dll?APPNAME=CampusNet&PRGNAME=COURSERESULTS&ARGUMENTS=-N518587923698845,-N000019', data="", headers=headers)
4142

4243
semester = {}
4344

@@ -54,7 +55,7 @@
5455
'Host': 'dualis.dhbw.de',
5556
'Cookie': cnsc,
5657
}
57-
response = requests.get(f'https://dualis.dhbw.de/scripts/mgrqispi.dll?APPNAME=CampusNet&PRGNAME=COURSERESULTS&ARGUMENTS=-N591469968597102,-N000307,-N{semester[semestername]}', data="", headers=headers) #get page with Prüfungen Table
58+
response = requests.get(f'https://dualis.dhbw.de/scripts/mgrqispi.dll?APPNAME=CampusNet&PRGNAME=COURSERESULTS&ARGUMENTS=-N518587923698845,-N000019,-N{semester[semestername]}', data="", headers=headers) #get page with Prüfungen Table
5859
temptable = re.findall('<table class="nb list">[\s\S]*</table>', response.text)[0] # extract table from html body
5960
temptable = re.findall('<tbody>[\s\S]*</tbody>', temptable)[0] # extract table body from table
6061
temprows = temptable.split('<tr')[1:-1] # extract all rows from table. [0] is just <tbody ...>
@@ -63,8 +64,13 @@
6364
tempcells = row.split('<td')[1:] # extract all columns from table
6465
currentrow = list()
6566
for cell in tempcells:
66-
cell = cell.split('>', 1)[1].split('</td')[0] # extract content from cell
67+
cell = cell.split('>', 1)[1].split('</td')[0].lstrip().rstrip() # extract content from cell, remove whitespaces from left and right
68+
if cell.startswith("<a"): #cell with the link
69+
cell = cell.split('href="', 1)[1].split('">')[0].replace("&amp;", "&") #only take content in a href="..." and convert url-encoding back to normal
6770
currentrow.append(cell) # combine cells to row
71+
currentrow = currentrow[:-1] # i know thats horrible coding, i dont know where that extra cell is from, please fix TODO
6872
table.append(currentrow) # combine rows to table
6973

74+
print(table)
75+
7076
## Get Prüfungen Results

0 commit comments

Comments
 (0)