News Feed Forums General Web Scraping Extract shipping fees from Amazon UK product pages using Node.js

  • Extract shipping fees from Amazon UK product pages using Node.js

    Posted by Shyamala Laura on 12/13/2024 at 8:01 am

    Scraping shipping fees from Amazon UK requires setting up a Node.js script using Puppeteer for efficient handling of dynamic content. Shipping fees are often displayed near the pricing section or as part of the delivery options on the product page. These fees may vary depending on the user’s location or the availability of specific delivery services. Puppeteer is ideal for this task because it enables the script to interact with the DOM and ensure all dynamic elements, such as shipping fees, are fully loaded before extraction.
    To start, the script opens the product page and waits for the specific section containing shipping information to appear. The selector for this section is identified through browser developer tools, typically targeting elements labeled as “Delivery” or “Shipping Fee.” Once the section is located, Puppeteer’s page.$eval function is used to extract the text content. The script can also be extended to simulate location-specific inputs, such as postal codes, to fetch shipping fees for different regions. Below is the complete implementation:

    const puppeteer = require('puppeteer');
    (async () => {
        const browser = await puppeteer.launch({ headless: true });
        const page = await browser.newPage();
        // Navigate to the Amazon UK product page
        await page.goto('https://www.amazon.co.uk/dp/product-page', {
            waitUntil: 'networkidle2'
        });
        // Wait for the shipping section to load
        await page.waitForSelector('.delivery-message');
        // Extract shipping fees
        const shippingFee = await page.$eval('.delivery-message', el => el.innerText.trim());
        console.log('Shipping Fee:', shippingFee);
        await browser.close();
    })();
    
    Minik Hamid replied 4 days, 17 hours ago 5 Members · 4 Replies
  • 4 Replies
  • Artur Mirjam

    Member
    12/13/2024 at 11:31 am

    The script could be extended to handle cases where shipping fees depend on the user’s location. Adding functionality to simulate entering different postal codes would allow the scraper to capture region-specific delivery charges. This would make the data more comprehensive for regional comparisons.

  • Mawunyo Ajdin

    Member
    12/14/2024 at 9:34 am

    Integrating error handling mechanisms would improve the robustness of the script. For example, if the shipping section fails to load or the selector changes, the script could log the error and attempt a retry. Additionally, capturing screenshots of the failed pages would assist in debugging.

  • Sanja Yevgeny

    Member
    12/17/2024 at 7:36 am

    Storing the scraped shipping data in a structured format like JSON or directly into a database would make it easier to analyze trends over time. This could be useful for businesses looking to compare shipping costs across multiple products or vendors.

  • Minik Hamid

    Member
    12/18/2024 at 7:11 am

    Enhancing the script with user-agent rotation and proxy support would improve its ability to avoid detection by Amazon’s anti-bot mechanisms. Since Amazon often implements measures to block automated requests, these features would help maintain access and ensure consistent results.

Log in to reply.