Created
June 19, 2014 01:32
-
-
Save bjhaid/2df85cd15c447b8ee013 to your computer and use it in GitHub Desktop.
Fifa world cup results parsed into JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'nokogiri' | |
require 'open-uri' | |
require 'json' | |
doc = Nokogiri::HTML(open('http://www.fifa.com/worldcup/matches/index.html')) | |
matches = doc.css('.mu').map do |row| | |
match = {} | |
match[:home_team_name] = row.css('.t.home').css('.t-nText').first.content | |
match[:home_team_code] = row.css('.t.home').css('.t-nTri').first.content | |
match[:home_team_flag_url] = row.css('.t.home').css('img').first['src'] | |
match[:away_team_name] = row.css('.t.away').css('.t-nText').first.content | |
match[:away_team_code] = row.css('.t.away').css('.t-nTri').first.content | |
match[:away_team_flag_url] = row.css('.t.away').css('img').first['src'] | |
match[:date_time] = row.css('.mu-i-datetime').first.content | |
match[:group] = row.css('.mu-i-group').first.content | |
match[:stadium] = row.css('.mu-i-stadium').first.content | |
match[:venue] = row.css('.mu-i-venue').first.content.strip | |
scores = row.css('span.s-scoreText').first.content | |
match[:scores] = scores if scores.include?("-") | |
match | |
end | |
puts JSON.pretty_generate(matches) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment