Как я могу получить несколько комментариев из обзоров Google Maps, используя Puppeteer? - PullRequest
0 голосов
/ 31 октября 2018

Я пытаюсь почистить все отзывы / комментарии из определенного места в Google Maps. Моя проблема в том, что я не уверен, какой тег использовать, чтобы получить все 62 отзыва / комментария в моем коде ниже (код работает, но я получаю 0 результатов при использовании window.scrollBy). Я получаю всю информацию с Google Maps:

const puppeteer = require('puppeteer'); // Require the Package we need...

let scrape = async () => { // Prepare scrape...

const browser = await puppeteer.launch({args: ['--no-sandbox', '--disabled-setuid-sandbox']}); // Prevent non-needed issues for *NIX
const page = await browser.newPage(); // Create request for the new page to obtain...

const busqueda = 'Alitas+del+Cadillac+Tumbaco';
const Url = `https://www.google.com/maps/search/${busqueda}`;

const buscar = '.section-result';
const click1 = '.widget-pane-link';
const cajaTexto = '#searchboxinput';

const comentarioLength = '.section-review-text';
const comentarios = 'div.section-review:nth-child(Index) > div:nth-child(1) > div:nth-child(3) > div:nth-child(2) > div:nth-child(1) > span:nth-child(4)';

console.log(comentarioLength);

//const comentario = 'div.section-review:nth-child(INDEX) > div:nth-child(1) > div:nth-child(3) > div:nth-child(2) > div:nth-child(1) > span:nth-child(4)';

// Replace with your Google Maps URL... Or Test the Microsoft one...
//await page.goto('https://www.google.com/maps/place/Microsoft/@36.1275216,-115.1728651,17z/data=!3m1!5s0x80c8c416a26be787:0x4392ab27a0ae83e0!4m7!3m6!1s0x80c8c4141f4642c5:0x764c3f951cfc6355!8m2!3d36.1275216!4d-115.1706764!9m1!1b1');

await page.goto(Url); // Define the Maps URL to Scrape...
await page.waitFor(2*1000); // In case Server has JS needed to be loaded...

await page.click(buscar); //busco caja de texto*/

await page.waitForNavigation();

await page.click(click1);

await page.waitForNavigation();

console.log(page.url());

console.log("3");

//div.section-result:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > h3:nth-child(1) > span:nth-child(1)


const result = await page.evaluate(() => { // Let's create variables and store values...

    let fullName = document.querySelector('.section-review-title').innerText; // Full Name
    let postDate = document.querySelector('.section-review-publish-date').innerText; // Date Posted
    let starRating = document.querySelector('.section-review-stars').getAttribute("aria-label"); // Star Rating
    let postReview = document.querySelector('.section-review-text').innerText; // Review Posted by Full Name aka Poster

    return { // Return the results...
        fullName,
        postDate,
        postReview,
        starRating
    }
});

await page.evaluate(_ => {
    window.scrollBy(0, window.innerHeight)
})

console.log('how many?', (await page.$$(buscar)).length)


browser.close(); // Close the Browser...
return result; // Return the results with the Review...
};

scrape().then((value) => { // Scrape and output the results...
console.log(value); // Yay, output the Results...
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...