Skip to content

Instantly share code, notes, and snippets.

@invalidusrname
Created March 24, 2017 19:12
Show Gist options
  • Select an option

  • Save invalidusrname/d389270838c39d2ec5c187ad1577c26d to your computer and use it in GitHub Desktop.

Select an option

Save invalidusrname/d389270838c39d2ec5c187ad1577c26d to your computer and use it in GitHub Desktop.
AT Spots
require 'open-uri'
require 'nokogiri'
url = 'http://www.summitpost.org/appalachian-trail-mileage-chart/593282'
css = 'noformat table'
doc = Nokogiri::HTML(open(url))
table = doc.css(css).detect { |e| e.text.include? 'Davenport' }
rows = table.css('tr')
first_row = rows.shift
data = rows.collect do |row|
row.css('td').collect { |e| e.text.to_s.gsub(',', '').strip }
end
data.each { |row| puts row * ',' }; nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment