Skip to content

Instantly share code, notes, and snippets.

@joshmn
Created June 5, 2014 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joshmn/f4eb8797939da1dadfb1 to your computer and use it in GitHub Desktop.
Save joshmn/f4eb8797939da1dadfb1 to your computer and use it in GitHub Desktop.
MLB Draft 2014: If teams were comprised solely of players they drafted (results of each team)
require 'httparty'
require 'nokogiri'
page = HTTParty.get('http://www.brewcrewball.com/2014/6/5/5328814/mlb-draft-players-roster-construction-brewers-yankees-red-sox-dodgers')
doc = Nokogiri::HTML(page.body)
i = 0
doc.css('#article-body h3').each do |t|
next if t.text.empty?
team = t.text
trs = doc.css('#article-body table')[i].css('tr')
rwar = 0.0
trs.each do |t|
if t.css('td')[0].text == "Position"
else
rwar += t.css('td').last.text.to_f
end
end
puts "#{team}: #{rwar.round}"
i += 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment