Created
May 5, 2015 03:49
-
-
Save michelleminkoff/7e934e88bf958496c10e to your computer and use it in GitHub Desktop.
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
#!/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