Skip to content

Instantly share code, notes, and snippets.

@briandunn
Created December 13, 2018 20:17
Show Gist options
  • Save briandunn/258220bd9e3bfd58d1fa70090f8170ba to your computer and use it in GitHub Desktop.
Save briandunn/258220bd9e3bfd58d1fa70090f8170ba to your computer and use it in GitHub Desktop.
read tacobell nutrition info from their web site
require 'open-uri'
require 'nokogiri'
doc = Nokogiri(URI('https://www.nutritionix.com/taco-bell/menu/premium').read)
headers = doc.css('thead th a span span[aria-hidden]').map do |header|
header.text.strip
end
rows = doc.css('tbody tr').map do |row|
values = row.css('td.col').map do |cell|
cell.text.gsub(/[^0-9]/,'').to_i
end
name = row.css('td.al a.nmItem').text.strip
next if name.empty?
{
name: name,
values: Hash[headers.zip(values)]
}
end.compact
pp rows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment