Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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