Last active
January 3, 2016 18:19
-
-
Save daz/8501219 to your computer and use it in GitHub Desktop.
Formula1 teams script. List all teams and drivers for the current year.
This file contains 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
# Dependencies | |
# | |
# $ gem install mechanize | |
# | |
# Usage | |
# | |
# $ git clone https://gist.github.com/8501219.git f1teams | |
# $ ruby f1teams/f1teams.rb | |
# | |
# Red Bull Racing | |
# Sebastian Vettel | |
# Daniel Ricciardo | |
# | |
# Lotus | |
# Romain Grosjean | |
# Pastor Maldonado | |
# | |
# Ferrari | |
# Kimi Räikkönen | |
# Fernando Alonso | |
require 'mechanize' | |
teams = {} | |
a = Mechanize.new | |
a.get('http://www.formula1.com/teams_and_drivers/') do |page| | |
page.search('.contentContainer').each do |node| | |
team_name = node.search('h4').text.strip.gsub(/\s+/, ' ') | |
drivers = node.search('.secondaryImage')[1..2].map { |n| n['alt'].strip } | |
teams[team_name] = drivers.reverse | |
end | |
end | |
teams.each do |team, drivers| | |
puts <<-TXT | |
#{team} | |
#{drivers[0]} | |
#{drivers[1]} | |
TXT | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment