Created
December 13, 2018 20:17
-
-
Save briandunn/258220bd9e3bfd58d1fa70090f8170ba to your computer and use it in GitHub Desktop.
read tacobell nutrition info from their web site
This file contains hidden or 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
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