News Feed Forums General Web Scraping How can I extract meal kit prices from HelloFresh.com using JavaScript?

  • How can I extract meal kit prices from HelloFresh.com using JavaScript?

    Posted by Rhea Erika on 12/20/2024 at 1:03 pm

    Scraping meal kit prices from HelloFresh.com using JavaScript allows you to collect data such as meal kit names, prices, and serving sizes. Using Node.js with Puppeteer, you can handle dynamic content rendering and automate browser interactions to extract relevant details. Below is a sample script for scraping meal kits from HelloFresh.

    const puppeteer = require('puppeteer');
    (async () => {
        const browser = await puppeteer.launch({ headless: true });
        const page = await browser.newPage();
        const url = 'https://www.hellofresh.com/plans';
        await page.goto(url, { waitUntil: 'networkidle2' });
        const meals = await page.evaluate(() => {
            const mealList = [];
            const items = document.querySelectorAll('.meal-card');
            items.forEach(item => {
                const name = item.querySelector('.meal-title')?.textContent.trim() || 'Name not available';
                const price = item.querySelector('.price')?.textContent.trim() || 'Price not available';
                const servings = item.querySelector('.servings')?.textContent.trim() || 'Servings not available';
                mealList.push({ name, price, servings });
            });
            return mealList;
        });
        console.log(meals);
        await browser.close();
    })();
    

    This script navigates to HelloFresh’s meal plans page, waits for content to load, and extracts meal names, prices, and serving sizes. Adding pagination handling or filters ensures the scraper collects data for all available meal plans. Random delays between requests reduce the risk of detection by anti-scraping mechanisms.

    Wulan Artabazos replied 2 weeks, 1 day ago 3 Members · 2 Replies
  • 2 Replies
  • Rita Lari

    Member
    12/27/2024 at 8:09 am

    Pagination handling is an important improvement for scraping meal data from HelloFresh. Meal plans and options are often distributed across multiple pages or sections, and automating navigation ensures a more complete dataset. Random delays between requests mimic human browsing behavior, reducing the risk of detection. This functionality enhances the scraper’s ability to collect detailed information about all available meal kits. Proper pagination handling makes the scraper more efficient and comprehensive.

  • Wulan Artabazos

    Member
    01/15/2025 at 1:56 pm

    Error handling ensures that the scraper works reliably even if HelloFresh updates its page layout. Missing elements like prices or serving sizes could cause the scraper to fail without proper checks. Adding conditions for null values allows the script to skip problematic entries and log them for review. Regular updates to the scraper ensure compatibility with any changes to HelloFresh’s website. These measures make the scraper more robust and dependable.

Log in to reply.