-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (42 loc) · 1.62 KB
/
index.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//importing dependencies
const puppeteer = require('puppeteer');
const fs = require('fs');
const gplay = require('google-play-scraper');
//ENTER THE APP ID HERE
const appId='com.shopify.mobile';
//main function for scraping
(async () => {
// code for launching a browser window(in chromium-default)
const browser = await puppeteer.launch({ headless: false });
// code to open a page in the browser
const page = await browser.newPage();
// redirect the page in to the website to be scrapped
await page.goto("https://play.google.com/store/apps/details?id="+appId);
// function to return the total number of reviews of the app
const reviewsCount = await page.evaluate(() => {
let reviewsCountContainer =document.querySelector(".AYi5wd.TBRnV > span");
let count= reviewsCountContainer.innerHTML;
return count;
});
//closing the chromium window
await browser.close();
//converting the count from comma separated string to number
let arr=reviewsCount.split(',');
let countInNumber=0;
arr.forEach((i)=> countInNumber=countInNumber+i);
//fetching the reviews
gplay.reviews({
appId: appId,
sort: gplay.sort.RATING,
num: parseInt(parseInt(countInNumber))
})
.then((reviews)=> {
//writing the reviews into the file
fs.writeFile("test.txt", JSON.stringify(reviews.data), function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
});
})();