-
How can I extract meal kit prices from HelloFresh.com using JavaScript?
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.
Sorry, there were no replies found.
Log in to reply.