-
What menu details can I scrape from Grubhub.com using Ruby?
Scraping menu details from Grubhub.com using Ruby allows you to collect restaurant names, menu items, and pricing. Ruby’s open-uri library for HTTP requests and nokogiri for parsing HTML makes the process efficient. Below is a sample script for extracting menu data from Grubhub.
require 'open-uri' require 'nokogiri' # Target URL url = "https://www.grubhub.com/" html = URI.open(url).read # Parse HTML doc = Nokogiri::HTML(html) # Extract restaurant and menu details doc.css('.restaurant-card').each do |restaurant| name = restaurant.css('.restaurant-name').text.strip rescue 'Name not available' menu_item = restaurant.css('.menu-item-name').text.strip rescue 'Menu item not available' price = restaurant.css('.menu-item-price').text.strip rescue 'Price not available' puts "Restaurant: #{name}, Menu Item: #{menu_item}, Price: #{price}" end
This script fetches Grubhub restaurant and menu details, parsing the page to extract names, menu items, and prices. Pagination or filtering by location can be added to gather more specific data. Adding delays between requests reduces the risk of detection by anti-scraping measures.
Sorry, there were no replies found.
Log in to reply.