Skip to content

Instantly share code, notes, and snippets.

@timrandg
Created October 8, 2013 09:23
Show Gist options
  • Save timrandg/6882026 to your computer and use it in GitHub Desktop.
Save timrandg/6882026 to your computer and use it in GitHub Desktop.
web parser challenge for Ben
require 'nokogiri'
require 'open-uri'
url = "http://www.nationsonline.org/oneworld/country_code_list.htm"
nodes = Nokogiri::XML(open(url))
#xml path to country table data nodes
table_data = "//td[@class='border1']"
country_data_nodes = nodes.search(table_data)
country_data_nodes.each_slice(5) do |n|
#n[0] is flag data, don't need, other text needs clean-up
n = n[1..4].collect{|n| n.text.strip}
puts "%-50s %5s %5s %5s" % n
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment