Get live NFL scores/stats to read and manipulate?

I know this is old, but this is what I use for scores only... maybe it will help someone some day. Note: there are some elements that you will not use and are specific for my site... but this would be a very good start for someone.

<?php
require('includes/application_top.php');
$week = (int)$_GET['week'];

//load source code, depending on the current week, of the website into a variable as a string
$url = "http://www.nfl.com/liveupdate/scorestrip/ss.xml"; //LIVE GAMES

if ($xmlData = file_get_contents($url)) {
$xml = simplexml_load_string($xmlData);
$json = json_encode($xml);
$games = json_decode($json, true);
}

$teamCodes = array(
'JAC' => 'JAX',
);

//build scores array, to group teams and scores together in games
$scores = array();
foreach ($games['gms']['g'] as $gameArray) {
$game = $gameArray['@attributes'];

//ONLY PULL SCORES FROM COMPLETED GAMES - F=FINAL, FO=FINAL OVERTIME
if ($game['q'] == 'F' || $game['q'] == 'FO') {
    $overtime = (($game['q'] == 'FO') ? 1 : 0);
    $away_team = $game['v'];
    $home_team = $game['h'];
    foreach ($teamCodes as $espnCode => $nflpCode) {
        if ($away_team == $espnCode) $away_team = $nflpCode;
        if ($home_team == $espnCode) $home_team = $nflpCode;
    }
    $away_score = (int)$game['vs'];
    $home_score = (int)$game['hs'];

    $winner = ($away_score > $home_score) ? $away_team : $home_team;
    $gameID = getGameIDByTeamID($week, $home_team);
    if (is_numeric(strip_tags($home_score)) && is_numeric(strip_tags($away_score))) {
            $scores[] = array(
                'gameID' => $gameID,
                'awayteam' => $away_team,
                'visitorScore' => $away_score,
                'hometeam' => $home_team,
                'homeScore' => $home_score,
                'overtime' => $overtime,
                'winner' => $winner
            );
    }
  }
}

//see how the scores array looks
//echo '<pre>' . print_r($scores, true) . '</pre>';
echo json_encode($scores);

//game results and winning teams can now be accessed from the scores array
//e.g. $scores[0]['awayteam'] contains the name of the away team (['awayteam'] part) from the first game on the page ([0] part)

Disclaimer: I'm the author of the tools I'm about to promote.

Over the past year, I've written a couple Python libraries that will do what you want. The first is nflgame, which gathers game data (including play-by-play) from NFL.com's GameCenter JSON feed. This includes active games where data is updated roughly every 15 seconds. nflgame has a wiki with some tips on getting started.

I released nflgame last year, and used it throughout last season. I think it is reasonably stable.

Over this past summer, I've worked on its more mature brother, nfldb. nfldb provides access to the same kind of data nflgame does, except it keeps everything stored in a relational database. nfldb also has a wiki, although it isn't entirely complete yet.

For example, this will output all current games and their scores:

import nfldb

db = nfldb.connect()

phase, year, week = nfldb.current(db)
q = nfldb.Query(db).game(season_year=year, season_type=phase, week=week)
for g in q.as_games():
    print '%s (%d) at %s (%d)' % (g.home_team, g.home_score,
                                  g.away_team, g.away_score)

Since no games are being played, that outputs all games for next week with 0 scores. This is the output with week=1: (of the 2013 season)

CLE (10) at MIA (23)
DET (34) at MIN (24)
NYJ (18) at TB (17)
BUF (21) at NE (23)
SD (28) at HOU (31)
STL (27) at ARI (24)
SF (34) at GB (28)
DAL (36) at NYG (31)
WAS (27) at PHI (33)
DEN (49) at BAL (27)
CHI (24) at CIN (21)
IND (21) at OAK (17)
JAC (2) at KC (28)
PIT (9) at TEN (16)
NO (23) at ATL (17)
CAR (7) at SEA (12)

Both are licensed under the WTFPL and are free to use for any purpose.

N.B. I realized you tagged this as PHP, but perhaps this will point you in the right direction. In particular, you could use nfldb to maintain a PostgreSQL database and query it with your PHP program.


I've spent the last year or so working on a simple CLI tool to easily create your own NFL databases. It currently supports PostgreSql and Mongo natively, and you can programmatically interact with the Engine if you'd like to extend it.

Want to create your own different database (eg MySql) using the Engine (or even use Postgres/Mongo but with your own schema)? Simply implement an interface and the Engine will do the work for you.

Running everything, including the database setup and updating with all the latest stats, can be done in a single command:

ffdb setup

I know this question is old, but I also realize that there's still a need out there for a functional and easy-to-use tool to do this. The entire reason I built this is to power my own football app in the near future, and hopefully this can help others.

Also, because the question is fairly old, a lot of the answers are not working at the current time, or reference projects that are no longer maintained.

Check out the github repo page for full details on how to download the program, the CLI commands, and other information:

FFDB Github Repository


So I found something that gives me MOST of what I was looking for. It has live game stats, but doesn't include current down, yards to go, and field position.

Regular Season: http://www.nfl.com/liveupdate/scorestrip/ss.xml

Post Season: http://www.nfl.com/liveupdate/scorestrip/postseason/ss.xml

I'd still like to find a live player stat feed to use to add Fantasy Football to my website, but I don't think a free one exists.