require 'mechanize' require 'json' agent = Mechanize.new osu_page = agent.get 'http://www.osu.edu' dining = osu_page.link_with(text: /Dining Halls/).click hours = dining.link_with(text: /Hours/).click nutrition = dining.link_with(text: /nutrition/i).click curl = agent.post 'https://dining.osu.edu/NetNutrition/1/Unit/SelectUnitFromUnitsList', {unitOid: 12} menu = JSON.parse curl.content menu_html = Nokogiri::HTML(menu['panels'][0]['html']) items = menu_html.css('.cbo_nn_itemHover') item = items[4]['onkeyup'][/event,(.*)\)/, 1] # get the id of 4th item in the menu label = agent.post 'https://dining.osu.edu/NetNutrition/1/NutritionDetail/ShowItemNutritionLabel', detailOid: item calories = label.css(".font-22") puts "#{items[4].text} has #{calories.text} calories"