Skip to content

Instantly share code, notes, and snippets.

@insanoid
Created April 9, 2014 17:53
Show Gist options
  • Save insanoid/10297012 to your computer and use it in GitHub Desktop.
Save insanoid/10297012 to your computer and use it in GitHub Desktop.
Node.JS Android Play Store
var request = require('request');
var cheerio = require('cheerio');
exports.getAppInfo = function(req, res) {
url = 'https://play.google.com/store/apps/details?id=' + req.param('appId') + '&&hl=en';
console.log('URL %s', url);
var json = {
app_name:"",
package_name: req.param('appId'),
icon: "",
category: "",
price:"",
developer_name:"",
rating: null,
installs: ""
};
request(url, function(error, response, html) {
if (!error) {
var $ = cheerio.load(html);
var title, release, rating;
$('.cover-image').filter(function() {
var data = $(this);
json.icon = data.attr('src');
})
$('.document-subtitle').filter(function() {
var data = $(this);
json.category = data.children('span').text();
})
$('.content[itemprop="numDownloads"]').filter(function() {
var data = $(this).filter(function(i, el) {
// this === el
return $(this).attr('itemprop') === 'numDownloads';
});
json.installs = data.text().trim();
})
$('meta[itemprop="price"]').filter(function() {
var data = $(this).filter(function(i, el) {
// this === el
return $(this).attr('itemprop') === 'price';
});
json.price = data.attr('content');
})
$('.current-rating').filter(function() {
var data = $(this);
if(!json.rating)
json.rating = Number(data.attr('style').replace(/[^0-9\.]+/g,""));
})
$('.document-title[itemprop="name"]').filter(function() {
var data = $(this);
json.app_name = data.text().trim();
})
$('span[itemprop="name"]').filter(function() {
var data = $(this);
json.developer_name = data.text().trim();
})
}
res.json(json);
})
}
@insanoid
Copy link
Author

insanoid commented Apr 9, 2014

Provides basic information about the app when method is called url/:appId for example com.example.app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment