News Feed Forums General Web Scraping How to scrape restaurant reviews from UberEats.com using JavaScript?

  • How to scrape restaurant reviews from UberEats.com using JavaScript?

    Posted by Ricardo Urbain on 12/21/2024 at 5:23 am

    Scraping restaurant reviews from UberEats.com using JavaScript allows you to collect data such as restaurant names, review ratings, and comments. Using Node.js with Puppeteer, you can automate browser interactions to handle dynamic content and extract relevant details. Below is a sample script for scraping UberEats reviews.

    const puppeteer = require('puppeteer');
    (async () => {
        const browser = await puppeteer.launch({ headless: true });
        const page = await browser.newPage();
        const url = 'https://www.ubereats.com/near-me';
        await page.goto(url, { waitUntil: 'networkidle2' });
        const reviews = await page.evaluate(() => {
            const reviewList = [];
            const items = document.querySelectorAll('.restaurant-card');
            items.forEach(item => {
                const name = item.querySelector('.restaurant-name')?.textContent.trim() || 'Name not available';
                const rating = item.querySelector('.review-rating')?.textContent.trim() || 'Rating not available';
                const comment = item.querySelector('.review-comment')?.textContent.trim() || 'Comment not available';
                reviewList.push({ name, rating, comment });
            });
            return reviewList;
        });
        console.log(reviews);
        await browser.close();
    })();
    

    This script navigates to UberEats’s restaurant listing page, waits for content to load, and extracts restaurant names, review ratings, and comments. Pagination handling ensures that you scrape data from multiple pages. Randomizing request timing helps avoid detection by UberEats’s anti-scraping systems.

    Ricardo Urbain replied 1 day, 18 hours ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.

Log in to reply.