File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,16 +31,20 @@ def extract_teams_and_scores(box_score_section, sport):
3131 period_scores = []
3232
3333 for row in score_table .find (TAG_TBODY ).find_all (TAG_TR ):
34- team_name_cell = row .find (TAG_TH ) if sport == 'ice hockey' else row .find (TAG_TD )
34+ # Check if team name is in <th> (some sports) or first <td> (other sports)
35+ team_name_cell = row .find (TAG_TH )
3536 if team_name_cell :
37+ # Team name is in <th>, all <td> elements are period scores
3638 team_name = team_name_cell .text .strip ().replace ("Winner" , "" ).strip ()
37- team_name = ' ' . join ( team_name . split ())
39+ scores = [ td . text . strip () for td in row . find_all ( TAG_TD )]
3840 else :
39- team_name = "Unknown"
41+ # Team name is in first <td>, remaining <td> elements are period scores
42+ team_name_cell = row .find (TAG_TD )
43+ team_name = team_name_cell .text .strip ().replace ("Winner" , "" ).strip () if team_name_cell else "Unknown"
44+ scores = [td .text .strip () for td in row .find_all (TAG_TD )[1 :]]
4045
46+ team_name = ' ' .join (team_name .split ())
4147 team_names .append (team_name )
42- scores = [td .text .strip () for td in row .find_all (TAG_TD )[1 :]]
43- scores = scores [:- 1 ] if sport == 'basketball' else scores
4448 period_scores .append (scores )
4549
4650 return team_names , period_scores
You can’t perform that action at this time.
0 commit comments