repl.it
@functorflow/

Google Play Store Review Scraper

Nodejs

No description

fork
loading
Files
  • index.js
  • Free_Bee_Google_2019-12-12.json
  • Packager files
  • package-lock.json
  • package.json
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
/*
* Don't run this on repl.it, run it on node cmd
* npm install google-play-scraper
* cd "Downloads/Free Bee Review Crawler"
* node crawler_google.js
*/

var fs = require('fs');
var util = require('util');
var path = './'; //change this path
var log_file = fs.createWriteStream(path+'Free_Bee_Google_'+(new Date().toISOString().split('T')[0])+'.json', {flags : 'w'});

var gplay = require('google-play-scraper');
let writeMe = "";

function loopy(page,bool) {
	gplay.reviews({
	  appId: 'com.pgc.freebee',
	  page: page,
	  sort: gplay.sort.NEWEST
	}).then(function(apps){
	  console.log('Retrieved ' + apps.length + ' reviews!');
	  if (apps.length == 0) {
	  	bool = true;
	  }
	  writeMe += util.format('%j',apps).replace(/[\[\]]/g, "") + ",";
	  var bracket = "";
	  if (page == 0) {
	  	bracket = "[";
	  }
	  if (apps.length != 0) {
	  	log_file.write(bracket);
	  }
	}).then(function(rev){
		page++;
		console.log(page);
		if(!bool) {
			loopy(page);
		}
	}).then(function(){
		if(bool) {
			log_file.write(writeMe.replace("},,","}]"));
		}
	}).catch(function(e){
	  console.log('There was an error fetching the reviews!');
	});
}

loopy(0);
?