nflscrapR (version 1.8.1)

scrape_game_play_by_play: Scrape an individual game's play-by-play data from NFL.com

Description

Depending on the year and type of the given game id, this function returns the play-by-play data available from NFL.com from either JSON (games starting in 2009) or parsed HTML (regular and post-season games starting in 1998, pre-season games starting in 2000). The necessary info regarding the game's play-by-play data to be scraped (type and season) is provided by the scrape_game_ids function. In addition to all of the play-level data provided by the NFL, outputs from the `nflscrapR` expected points and win probability models are also included, allowing an individual to conduct their own analysis with more advanced football statistics. A detailed description of the models methodologies can be found here: https://arxiv.org/abs/1802.00998. This function acts as a wrapper function for the scrape_json_play_by_play and scrape_html_play_by_play functions, deciding which to use depending on the input.

Usage

scrape_game_play_by_play(game_id, type, season, check_url = 1)

Arguments

game_id

Ten digit game id (either numeric or character) associated with a given NFL game.

type

String indicating the type of game, must either be: "pre", "reg", or "post". This argument is required for entry to ensure proper handling of the type of play-by-play data for the given game.

season

Numeric 4-digit year associated with an NFL season for the given game id.

check_url

Indicator for whether or not to check if the game's url exists (default is 1, meaning yes). This is used to work with the scrape_season_play_by_play function that will perform its own check prior to scraping individual games.

Value

Data frame where each individual row represents a single play in the game containing detailed information depending on the availability of data for the game. See scrape_json_play_by_play and scrape_html_play_by_play for documentation about the columns returned.

Examples

Run this code
# NOT RUN {
# Scrape the play-by-play data for the 2017 Super Bowl by first getting all
# of the post-season game ids then use the required info to scrape the 
# play-by-play data (knowing that it's the last game):
playoff_game_ids_17 <- scrape_game_ids(2017, type = "post")
sb_17_id <- playoff_game_ids_17$game_id[nrow(playoff_game_ids_17)]
sb_17_pbp <- scrape_game_play_by_play(game_id = sb_17_id, type = "post", 
                                      season = 2017)
# }

Run the code above in your browser using DataLab