
Security News
Nx npm Packages Compromised in Supply Chain Attack Weaponizing AI CLI Tools
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
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...
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.
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" => ...
# }
You can get all the conferences in NCAA D1 Men's Basketball.
ESPN.get_conferences_in_ncb
# => [{:name=>"America East", :data_name=>"1"},
# {:name=>"American", :data_name=>"62"},
# ...
# ]
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" => ...
# }
All score requests return an array of hashes. Here's an example NFL score hash:
{
league: 'nfl',
game_date: #<DateTime: 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.
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)
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') )
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'
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'
Running tests:
rake test
Re-building the gem and installing locally:
gem build espn_scraper.gemspec
gem uninstall espn_scraper
gem install espn_scraper-x.x.x.gem
Future plans:
MIT License
FAQs
Unknown package
We found that espn_scraper demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.