def retrieve_box_score(driver, team, date): # ensure that there are games on this day for div in driver.find_elements_by_css_selector('div.ng-scope .col-sm-12.no-games.ng-scope'): if 'No Games Scheduled' in div.text: print 'No games scheduled for {} on {}'.format(team, date_to_slash_notation(date)) return # find the team you were looking for by first collecting all the div footers games_list = driver.find_elements_by_css_selector('div.game-header.clearfix + div') found_game = False for game in games_list: if team in game.text: footer = game.parent.find_element_by_css_selector('.game-footer') box_score_link = footer.find_element_by_link_text('Box Score').get_attribute('href') open_new_tab(driver) driver.get(box_score_link) parse_traditional_box_score(driver.page_source) close_current_tab(driver) found_game = True break if not found_game: print 'No games scheduled for {} on {}'.format(team, date_to_slash_notation(date)) print 'Collected box score for {} on date {}'.format(team, date)
from parser.nba_box_score import parse_traditional_box_score, parse_advanced_box_score, \ parse_misc_box_score, parse_usage_box_score, parse_four_factors, parse_scoring_box_score, parse_player_tracking from parser.play_by_play import parse_play_by_play from json import dumps if __name__ == '__main__': game = None with open('./test/box_score_traditional.html') as f: html_page = '\n'.join([line for line in f]) game = parse_traditional_box_score(html_page, game) with open('./test/box_score_advanced.html') as f: html_page = '\n'.join([line for line in f]) game = parse_advanced_box_score(html_page, game) with open('./test/box_score_misc.html') as f: html_page = '\n'.join([line for line in f]) game = parse_misc_box_score(html_page, game) with open('./test/box_score_scoring.html') as f: html_page = '\n'.join([line for line in f]) game = parse_scoring_box_score(html_page, game) with open('./test/box_score_usage.html') as f: html_page = '\n'.join([line for line in f]) game = parse_usage_box_score(html_page, game) with open('./test/box_score_four_factors.html') as f: html_page = '\n'.join([line for line in f]) game = parse_four_factors(html_page, game)