22
33
44def parse_grade_history (html : str ) -> dict [str , str ]:
5- soup = BeautifulSoup (html , 'html.parser' )
6- table = soup .find ('table' , {'class' : 'table table-hover table-bordered' })
7- # Extract the row containing the desired data
8- data_row = table .find ('tbody' ).find ('tr' )
9- # Extract the specific data points
10- columns = data_row .find_all ('td' )
11- grades : dict [str , str ]= {
12- 'credits_registered' : columns [0 ].get_text (strip = True ),
13- 'credits_earned' : columns [1 ].get_text (strip = True ),
14- 'cgpa' : columns [2 ].get_text (strip = True )
15- }
5+ try :
6+ soup = BeautifulSoup (html , 'html.parser' )
7+ table = soup .find ('table' , {'class' : 'table table-hover table-bordered' })
8+ # Extract the row containing the desired data
9+ data_row = table .find ('tbody' ).find ('tr' )
10+ # Extract the specific data points
11+ columns = data_row .find_all ('td' )
12+ grades : dict [str , str ]= {
13+ 'credits_registered' : columns [0 ].get_text (strip = True ),
14+ 'credits_earned' : columns [1 ].get_text (strip = True ),
15+ 'cgpa' : columns [2 ].get_text (strip = True )
16+ }
1617
17- return grades
18+ return grades
19+ except Exception as e :
20+ print (f"Error parsing grade history: { str (e )} " )
21+ return {
22+ 'credits_registered' : "N/A" ,
23+ 'credits_earned' : "N/A" ,
24+ 'cgpa' : "N/A"
25+ }
0 commit comments