Created
April 9, 2014 17:53
-
-
Save insanoid/10297012 to your computer and use it in GitHub Desktop.
Node.JS Android Play Store
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Provides basic information about the app when method is called url/:appId for example com.example.app.