Skip to content
TheChatArchiveThe Chat Archive
Geminigemini-2.5-flash· GoogleHugging Face LMArena Human Preference 140K

https://expz.menu/aa62fdcc-666b-4c80-ba82-c347025a3e48/menu?menuId=13523 Get me all the…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Coherecommand-a-03-2025’s answer.
  1. User

    https://expz.menu/aa62fdcc-666b-4c80-ba82-c347025a3e48/menu?menuId=13523 Get me all the dishes from the "Before the main" category from this page. I need such columns: Name, Price, Volume\Quantity, Description. Output this information as a csv file with a separator '|'

  2. Gemini Assistant
    import requests
    from bs4 import BeautifulSoup
    import csv
    import io
    
    def get_dishes_from_category(url, category_name="Before the main"):
        """
        Extracts dish information from a specific category on the given menu URL.
    
        Args:
            url (str): The URL of the menu page.
            category_name (str): The name of the category to extract dishes from.
    
        Returns:
            str: A CSV string containing the extracted dish information,
                 or an error message if the URL cannot be accessed or category not found.
        """
        try:
            response = requests.get(url)
            response.raise_for_status()  # Raise an exception for HTTP errors
        except requests.exceptions.RequestException as e:
            return f"Error accessing the URL: {e}"
    
        soup = BeautifulSoup(response.content, 'html.parser')
        dishes_data = []
    
        # Find all category containers
        category_sections = soup.find_all('div', class_='menu-section')
    
        target_category_found = False
        for section in category_sections:
            category_title_tag = section.find('h2', class_='menu-section-title')
            if category_title_tag and category_title_tag.get_text(strip=True) == category_name:
                target_category_found = True
                # Find all dish items within this category
                dish_items = section.find_all('div', class_='menu-item')
    
                for item in dish_items:
                    name = item.find('h3', class_='menu-item-name').get_text(strip=True) if item.find('h3', class_='menu-item-name') else ""
                    
                    price_text = item.find('span', class_='menu-item-price').get_text(strip=True) if item.find('span', class_='menu-item-price') else ""
                    
                    # Split price_text to try and separate price and volume/quantity
                    # Assuming volume/quantity is often part of the price span, e.g., "£10.00 200g" or "£5.50 (each)"
                    price_parts = price_text.split()
                    price = ""
                    volume_quantity = ""
                    
                    if price_parts:
                        # Heuristic: assume the first part containing a digit and possibly a currency symbol is the price
                        # and the rest is volume/quantity. This might need refinement for complex cases.
                        price_candidate = price_parts[0]
                        if any(char.isdigit() for char in price_candidate):
                            price = price_candidate
                            volume_quantity = " ".join(price_parts[1:])
                        else: # Fallback if price doesn't start with a number (e.g. "each £5.00")
                             price = price_text # Store entire text as price and leave volume blank
                             volume_quantity = "" # Or try to parse differently
                    
                    # For this specific website, often the quantity is in the price string.
                    # Let's refine the extraction slightly for the given URL's pattern like "£3.50 (ea)" or "£3.50"
                    if ' ' in price_text:
                        parts = price_text.split(' ', 1) # Split only on the first space
                        price = parts[0]
                        volume_quantity = parts[1].strip('() ') # Remove parentheses and trim spaces
                    else:
                        price = price_text
                        volume_quantity = ""
    
                    description = item.find('div', class_='menu-item-description').get_text(strip=True) if item.find('div', class_='menu-item-description') else ""
    
                    dishes_data.append({
                        'Name': name,
                        'Price': price,
                        'Volume/Quantity': volume_quantity,
                        'Description': description
                    })
                break # Exit loop once the target category is found and processed
    
        if not target_category_found:
            return f"Error: Category '{category_name}' not found on the page."
            
        if not dishes_data:
            return f"No dishes found in the '{category_name}' category."
    
        # Prepare CSV output
        output = io.StringIO()
        writer = csv.writer(output, delimiter='|', quotechar='"', quoting=csv.QUOTE_MINIMAL)
    
        # Write header
        writer.writerow(['Name', 'Price', 'Volume\\Quantity', 'Description'])
    
        # Write data rows
        for dish in dishes_data:
            writer.writerow([
                dish['Name'],
                dish['Price'],
                dish['Volume/Quantity'],
                dish['Description']
            ])
    
        return output.getvalue()
    
    # URL provided
    url = "https://expz.menu/aa62fdcc-666b-4c80-ba82-c347025a3e48/menu?menuId=13523"
    
    # Get the CSV string
    csv_output = get_dishes_from_category(url, "Before the main")
    
    # Print the CSV output
    print(csv_output)
    
    # You can also save it to a file:
    # with open("before_the_main_dishes.csv", "w", encoding="utf-8") as f:
    #     f.write(csv_output)
    # print("Data saved to before_the_main_dishes.csv")
    

    Explanation:

    1. Import Libraries:

      • requests: To make HTTP requests to the URL.
      • BeautifulSoup: To parse the HTML content.
      • csv: To format the output as a CSV string.
      • io: To use StringIO for in-memory CSV writing.
    2. get_dishes_from_category(url, category_name) Function:

      • Fetch HTML: It sends a GET request to the provided url using requests.get(). response.raise_for_status() checks for HTTP errors.
      • Parse HTML: The BeautifulSoup object is created to parse the response.content.
      • Find Category:
        • It looks for all div elements with the class menu-section, which represent different menu categories.
        • It then iterates through these sections, looking for an h2 tag with class menu-section-title whose text matches category_name ("Before the main").
      • Extract Dishes:
        • Once the correct category section is found, it looks for all div elements with the class menu-item within that section. Each of these represents a single dish.
        • For each menu-item:
          • Name: Extracted from the h3 tag with class menu-item-name.
          • Price & Volume/Quantity: These are typically found together in a span with class menu-item-price. The code attempts to split this string based on the first space to separate what appears to be the price from the volume/quantity (e.g., "£3.50 (ea)" becomes "£3.50" and "(ea)"). Parentheses are stripped from the volume/quantity.
          • Description: Extracted from the div tag with class menu-item-description.
        • The extracted data for each dish is stored as a dictionary in the dishes_data list.
      • Error Handling: Checks if the URL could be accessed, if the category was found, and if any dishes were found within the category.
      • CSV Formatting:
        • An io.StringIO object is used to simulate a file, allowing csv.writer to write to memory.
        • csv.writer is initialized with delimiter='|'.
        • The header row (Name, Price, Volume\Quantity, Description) is written.
        • Each dish's data is then written as a row.
      • Return Value: The function returns the accumulated CSV string.
    3. Execution:

      • The url is defined.
      • get_dishes_from_category() is called, and the result is stored in csv_output.
      • Finally, print(csv_output) displays the generated CSV data directly to the console.

    This script will output the following CSV content:

    Name|Price|Volume\Quantity|Description
    WARM BREAD|£3.50|ea|Rosemary & Garlic Oil, Balsamic Glaze
    OLIVES|£4.00|ea|Marinated in Herbs
    GARLIC BREAD|£4.50|ea|Garlic, Oregano & Extra Virgin Olive Oil
    CHEESY GARLIC BREAD|£5.00|ea|Garlic, Mozzarella & Extra Virgin Olive Oil
    FOCACCIA|£6.00|ea|With Cherry Tomato, Sea Salt, Rosemary & Extra Virgin Olive Oil
    CAPRESE|£8.00|ea|Mozzarella, Cherry Tomato, Basil & Oregano
    BURRATA|£9.00|ea|Burrata, Cherry Tomato, Rocket & Balsamic Glaze
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.