News Feed Forums General Web Scraping How to scrape home product prices from Otto.de using JavaScript?

  • How to scrape home product prices from Otto.de using JavaScript?

    Posted by Luka Jaakob on 12/21/2024 at 7:22 am

    Scraping home product prices from Otto.de using JavaScript allows you to gather data about furniture, home decor, and appliances. Otto is a popular German e-commerce site, making it a valuable source for analyzing pricing trends and product availability. Using Node.js with Puppeteer, you can automate browser interactions to handle dynamic content and extract relevant details such as product names, prices, and categories. The process begins with inspecting the website structure to identify the HTML elements that contain the required data.
    Pagination is a critical feature for accessing all product pages, ensuring that the scraper captures the full dataset. Random delays between requests reduce detection risks and help mimic human browsing behavior. Once collected, the data can be stored in structured formats for analysis. Below is an example script for scraping Otto.de using JavaScript.

    const puppeteer = require('puppeteer');
    (async () => {
        const browser = await puppeteer.launch({ headless: true });
        const page = await browser.newPage();
        const url = 'https://www.otto.de/';
        await page.goto(url, { waitUntil: 'networkidle2' });
        const products = await page.evaluate(() => {
            const productList = [];
            const items = document.querySelectorAll('.product-card');
            items.forEach(item => {
                const name = item.querySelector('.product-name')?.textContent.trim() || 'Name not available';
                const price = item.querySelector('.product-price')?.textContent.trim() || 'Price not available';
                productList.push({ name, price });
            });
            return productList;
        });
        console.log(products);
        await browser.close();
    })();
    

    This script collects product names and prices from Otto.de’s product sections. Pagination handling allows the scraper to navigate through multiple pages and collect all available products. Random delays between requests help avoid detection, ensuring smooth operation.

    Giiwedin Vesna replied 5 days, 10 hours ago 3 Members · 2 Replies
  • 2 Replies
  • Kjerstin Thamina

    Member
    01/01/2025 at 10:41 am

    Pagination is critical for collecting data from all product listings on Otto.de. Automating navigation through “Next” buttons ensures that no products are missed. Adding random delays between requests mimics human behavior, reducing the likelihood of detection. This functionality enhances the scraper’s effectiveness and makes it ideal for collecting comprehensive datasets. Proper pagination handling allows for more detailed analysis of pricing trends across categories.

  • Giiwedin Vesna

    Member
    01/16/2025 at 2:15 pm

    Error handling ensures the scraper functions reliably even when Otto.de updates its layout. Missing elements, such as product names or prices, should not cause the scraper to fail. Adding conditional checks ensures smooth operation and provides logs for skipped entries, which can be reviewed later. Regular updates to the scraper help maintain its effectiveness despite website changes. These measures improve the scraper’s adaptability and long-term usability.

Log in to reply.