-
Extract shipping fees from Amazon UK product pages using Node.js
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(); })();
Log in to reply.