-
Scrape customer reviews from Tesco Lotus Thailand using Node.js and Puppeteer?
When scraping Tesco Lotus Thailand, Puppeteer is a powerful tool for handling dynamically loaded content, such as customer reviews. The site often uses JavaScript to load reviews, so you’ll need to make sure you wait for all content to load before attempting to scrape it. After navigating to the product page, you can extract review details like rating, text, and reviewer name using page.evaluate(). It’s important to handle scenarios where reviews might span multiple pages, which can be done by simulating user scrolling or clicking on pagination links.
const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch({ headless: false }); const page = await browser.newPage(); await page.goto('https://www.tescolotus.com/product-page'); // Wait for the review section to load await page.waitForSelector('.review-item'); // Scrape reviews const reviews = await page.evaluate(() => { const reviewElements = document.querySelectorAll('.review-item'); const reviewData = []; reviewElements.forEach(element => { const name = element.querySelector('.reviewer-name')?.innerText; const rating = element.querySelector('.rating-stars')?.innerText; const reviewText = element.querySelector('.review-text')?.innerText; reviewData.push({ name, rating, reviewText }); }); return reviewData; }); console.log(reviews); await browser.close(); })();
Log in to reply.