Skip to content

Instantly share code, notes, and snippets.

@michelleminkoff
Created May 5, 2015 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michelleminkoff/7e934e88bf958496c10e to your computer and use it in GitHub Desktop.
Save michelleminkoff/7e934e88bf958496c10e to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'nokogiri'
require 'rubygems'
require 'open-uri'
require 'csv'
CSV.open("myfile.csv", "w") do |csv|
page = Nokogiri::HTML(open("http://www.cbp.gov/newsroom/stats/southwest-border-unaccompanied-children"))
headingList = []
page.css("table")[0].css("th").each{|heading|
headingList.push(heading.text)
}
csv << headingList
tableRows = page.css("table")[0].css('tr').each{|row|
data = []
row.css('td').each_with_index{|item, column_index|
data.push(item.text)
}
csv << data.to_a
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment