-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathscrape.js
More file actions
35 lines (26 loc) · 1.61 KB
/
scrape.js
File metadata and controls
35 lines (26 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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...
// 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('http://URL-TO-GOOGLE-MAPS-URL-HERE'); // Define the Maps URL to Scrape...
await page.waitFor(1000); // In case Server has JS needed to be loaded...
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
}
});
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...
});