When scraping Shopee Thailand, product reviews can be accessed by navigating through the product page and extracting review data. Puppeteer allows you to emulate user actions like scrolling, ensuring that all reviews load before extracting them. You can gather product ratings and user comments by targeting the right classes and using page.$eval() or page.$$eval() to fetch the review content.
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.goto('https://shopee.co.th/product-page-url');
// Scroll to load reviews
await page.evaluate(() => {
window.scrollBy(0, window.innerHeight);
});
// Scrape reviews
const reviews = await page.$$eval('.review-item', items => {
return items.map(item => {
const name = item.querySelector('.review-author').innerText;
const rating = item.querySelector('.rating-star').innerText;
const reviewText = item.querySelector('.review-text').innerText;
return { name, rating, reviewText };
});
});
console.log(reviews);
await browser.close();
})();