-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
113 lines (96 loc) · 3 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
var request = require('request');
var cheerio = require('cheerio');
var qs = require('querystring');
module.exports = {
getAppData: function(bundleId, cb) {
var baseUrl = 'https://play.google.com/store/apps/details?id=';
request(baseUrl + bundleId, function(err, res, html) {
if (err) {
cb(err);
return;
}
if (res.statusCode == 404) {
cb(null, null);
return;
}
var app = {
packageId: bundleId,
appName: null,
developer: null,
category: null,
logo: null,
price: null,
inAppPurchases: null,
playStoreUrl: null,
description: null,
screenshots: null,
ratingValue: null,
ratingCount: null,
score: null,
datePublished: null,
fileSize: null,
numDownloads: null,
softwareVersion: null,
operatingSystems: null,
contentRating: null,
developerLinks: null,
developerEmail: null
};
try {
var $ = cheerio.load(html);
app.appName = $('.document-title div').html();
app.developer = $('.document-subtitle.primary span').html();
app.category = $('.document-subtitle.category span').html();
app.logo = $('.details-info img.cover-image').attr('src');
// price
var spans = $('.info-container .buy-button-container button.price.buy span');
var contents = $(spans[spans.length -1]).html();
var idx = contents.indexOf(' Buy');
var price = contents.substr(0, idx);
app.price = price.length > 0 ? price : 'free';
//
app.inAppPurchases = !(!$('.inapp-msg').html());
app.playStoreUrl = baseUrl + bundleId;
app.description = $('.id-app-orig-desc').html();
app.screenshots = [];
$('.thumbnails img').each(function(i, item) {
app.screenshots.push($(item).attr('src'));
});
app.ratingCount = $('.details-section.reviews meta[itemprop=ratingCount]').attr('content');
app.ratingValue = $('.details-section.reviews meta[itemprop=ratingValue]').attr('content');
app.score = $('.details-section.reviews .score').html();
// meta data
var meta = {};
$('.meta-info').each(function(i, item) {
var prop = $('.title', item).html().trim().toLowerCase().replace(' ', '_');
var val = $('.content', item).html().trim();
meta[prop] = val;
});
app.datePublished = meta.updated;
app.fileSize = meta.size;
app.numDownloads = meta.installs;
app.softwareVersion = meta.current_version;
app.operatingSystems = meta.require_android;
app.contentRating = meta.content_rating;
app.developerLinks = [];
// developer contact info
$('.dev-link').each(function(i, item) {
var href = $(item).attr('href');
if (href && href.indexOf('mailto:') > -1) {
app.developerEmail = href.substr(7);
} else {
var parsed = qs.parse(href);
app.developerLinks.push(parsed['https://www.google.com/url?q']);
}
});
} catch (ex) {
var error = new Error('Error scraping Play Store');
error.inner = ex;
cb(error);
return;
}
cb(err, app);
return;
});
}
};