News Feed Forums General Web Scraping What menu details can I scrape from Grubhub.com using Ruby?

  • What menu details can I scrape from Grubhub.com using Ruby?

    Posted by Anwar Riya on 12/21/2024 at 5:14 am

    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.

    Anwar Riya replied 1 day, 17 hours ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.

Log in to reply.