GithubHelp home page GithubHelp logo

espn-scraper's Introduction

ESPN Scraper

ESPN Scraper is a simple gem for scraping teams and scores from ESPN's website. Please note that ESPN is not involved with this gem or me in any way. I chose ESPN because it is a leader in sports statistics and has a robust website.

ESPN.responding?
# => true

Lets begin...

Supported leagues

The gem only supports the following leagues:

ESPN.leagues
# => [ "nfl", "mlb", "nba", "nhl", "ncf", "ncb" ]

Which are the NFL, MLB, NBA, NHL, NCAA D1 Football, NCAA D1 Men's Basketball respectively.

Scrape Divisions

You can get all the divisions in each league.

ESPN.get_divisions
# => {
#   "nfl" => [
#     { :name => "NFC East", :data_name => "nfc-east" },
#     { :name => "NFC West", :data_name => "nfc-west" },
#     ...
#   ],
#   "mlb" => ...
# }

Scrape teams

You can get the teams in each league by acronym. It returns a hash of each division with an array of hashes for each team in the division.

ESPN.get_teams_in('nba')
# => {
#   "atlantic"=> [ 
#     { :name => "Boston Celtics", :data_name => "bos" },  
#     { :name => "Brooklyn Nets", :data_name => "bkn" }, 
#     { :name => "New York Knicks", :data_name => "ny" }, 
#     { :name => "Philadelphia 76ers", :data_name => "phi" }, 
#     { :name => "Toronto Raptors", :data_name => "tor" }
#   ]
#   "pacific" => ...
# }

Scraping scores

All score requests return an array of hashes. Here's an example NFL score hash:

{
  league: 'nfl',
  game_date: #<Date: 2012-10-25>,
  home_team: 'min',
  home_score: 17,
  away_team: 'tb',
  away_score: 36
}

You'll notice the teams are identified with the same :data_name from a ESPN.get_teams_in request. One issue with scraping scores is that football goes by year and week, and baseball, basketball, hockey go by date.

weekly (football)

Pattern is ESPN.get_<league>_scores(year, week). This is for nfl and ncf:

ESPN.get_nfl_scores(2012, 8)
ESPN.get_ncf_scores(2011, 3)
daily (baseball, basketball, hockey)

Pattern is ESPN.get_<league>_scores(date). This is for mlb, nba, nhl, ncb:

ESPN.get_mlb_scores( Date.parse('Aug 13, 2012') )
ESPN.get_nba_scores( Date.parse('Dec 25, 2011') )
ESPN.get_nhl_scores( Date.parse('Feb 14, 2009') )
ESPN.get_ncb_scores( Date.parse('Mar 15, 2012') )

Installing

Add the gem to your Gemfile

gem 'espn_scraper', git: 'git://github.com/aj0strow/espn-scraper.git'
# or
gem 'espn_scraper', github: 'aj0strow/espn-scraper'

..and then require it. I personally use it in rake tasks of a Rails app.

require 'espn_scraper'

Contributing

Please report back if something breaks on you!

Also please let me know if any of the data names get outdated. For instance a bunch of NFL data names were recently changed. You can make fixes temporarily with the following:

ESPN::DATA_NAME_FIXES['nfl']['gnb'] = 'gb'

Future plans:

  • Get start and end dates of a season

espn-scraper's People

Contributors

aj0strow avatar lievcin avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.