14

我需要某种数据库或提要来访问 NFL 的实时比分(可能还有球员统计数据)。我希望能够在我的网站上显示我的pickem 联赛的分数,并向用户显示他们的选择是否获胜。

我不知道该怎么做。有人可以指出我正确的方向吗?

此外,它必须是免费的。

4

7 回答 7

23

免责声明:我是我即将推广的工具的作者。

在过去的一年里,我编写了几个 Python 库来满足你的需求。第一个是nflgame,它从 NFL.com 的 GameCenter JSON 提要收集游戏数据(包括逐个播放)。这包括数据大约每 15 秒更新一次的活跃游戏。nflgame有一个 wiki,其中包含一些入门技巧。

我去年发布了 nflgame,并在上个赛季一直使用它。我认为它是相当稳定的。

在过去的这个夏天,我研究了它更成熟的兄弟nfldb。nfldb 提供对 nflgame 所提供的相同类型数据的访问,除了它将所有内容存储在关系数据库中。nfldb也有一个 wiki,虽然它还没有完全完成。

例如,这将输出所有当前游戏及其分数:

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)

由于没有比赛正在进行,因此将输出下周的所有比赛以及0得分。这是输出week=1:(2013 赛季)

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)

两者都在 WTFPL 下获得许可,并且可以免费用于任何目的。

注意,我意识到您将其标记为 PHP,但也许这会为您指明正确的方向。特别是,您可以nfldb用来维护一个 PostgreSQL 数据库并使用您的 PHP 程序对其进行查询。

于 2013-09-12T05:58:09.930 回答
4

因此,我找到了一些可以满足我大部分需求的东西。它有现场比赛统计数据,但不包括当前的下降、要走的码数和场地位置。

常规赛: http ://www.nfl.com/liveupdate/scorestrip/ss.xml

季后赛: http ://www.nfl.com/liveupdate/scorestrip/postseason/ss.xml

我仍然想找到一个现场球员统计信息源,用于将 Fantasy Football 添加到我的网站,但我认为不存在免费的。

于 2014-01-24T20:57:59.980 回答
4

我知道这是旧的,但这是我只用于分数的......也许有一天它会帮助某人。注意:有些元素您不会使用,并且是特定于我的网站的......但这对某人来说是一个非常好的开始。

<?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)
于 2015-09-29T01:22:47.560 回答
1

过去一年左右,我一直在研究一个简单的 CLI 工具,以轻松创建您自己的 NFL 数据库。它目前原生支持 PostgreSql 和 Mongo,如果你想扩展它,你可以通过编程方式与引擎交互。

想要使用引擎创建您自己的不同数据库(例如 MySql)(或者甚至使用 Postgres/Mongo,但使用您自己的架构)?只需实现一个接口,引擎就会为您完成工作。

运行所有内容,包括数据库设置和使用所有最新统计信息更新,都可以在一个命令中完成:

ffdb setup

我知道这个问题很老,但我也意识到仍然需要一个功能强大且易于使用的工具来做到这一点。我构建它的全部原因是为了在不久的将来为我自己的足球应用程序提供动力,希望这可以帮助其他人。

此外,由于这个问题相当老,很多答案目前都不起作用,或者参考项目不再维护。

查看 github repo 页面以获取有关如何下载程序、CLI 命令和其他信息的完整详细信息:

FFDB Github 存储库

于 2019-03-27T04:26:36.120 回答
0
$XML = "http://www.nfl.com/liveupdate/scorestrip/ss.xml";
$lineXML = file_get_contents($XML);
$subject = $lineXML;
//match and capture week then print
$week='/w="([0-9])/';
preg_match_all($week, $subject, $week);
echo "week ".$week[1][0]."<br/>"; 
$week2=$week[1][0];
echo $week2; 

//capture team, scores in two dimensional array  
$pattern = '/hnn="(.+)"\shs="([0-9]+)"\sv="[A-Z]+"\svnn="(.+)"\svs="([0-9]+)/';
preg_match_all($pattern, $subject, $matches);

//enumerate length of array (number games played)
$count= count($matches[0]);

 //print array values
 for ($x = 0; $x < $count ; $x++) {
         echo"<br/>";
         //print home team
         echo $matches[1][$x],"   ",
         //print home score
         $matches[2][$x],"   ",
         //print visitor team
         $matches[3][$x],"   ",
         //print visitor score
         $matches[4][$x];
         echo "<br/>";

       }
于 2018-09-19T01:48:21.183 回答
0

我在寻找 2021 赛季的新来源时遇到了问题。好吧,我终于在 ESPN 上找到了一个。

http://site.api.espn.com/apis/site/v2/sports/football/nfl/scoreboard

以 JSON 格式返回结果。

于 2021-09-13T02:30:07.717 回答
-3

我建议在http://developer.espn.com注册并访问他们的 JSON API。我只花了 5 分钟,他们有文件可以打你需要的任何电话。

于 2014-01-02T21:38:46.060 回答