Getting app information from Google play store by Url

Posted By : Pankaj Kumar Yadav | 24-Jun-2015

Hello,

In this blog I am going to get App information from Google play store like app name, App icon url, app price etc.

First of all We need Jsoup jar.

Now here are the steps to retrived app data.

Step 1:- Add Jsoup jar to your project.

Step 2:- Now we need the app url at Google play store

Suppose we new to get Trendr App Data then we need trandr app url at Google play store ie https://play.google.com/store/apps/details?id=com.prestigeapp&hl=en.

Step 3:- Now use the following code to get data. And import org.jsoup.Jsoup.

def readAppInfoByAppUrl(){
        String url  = 'https://play.google.com/store/apps/details?id=com.prestigeapp&hl=en.' // App url here
        def appData = [:]
        def index = url.lastIndexOf('?id=')
        def appBunddleID = url.substring(index+4)  // App bunddleID
        def htmlPage = Jsoup.connect(url).get(); // Parsing html
        def description = htmlPage.select("div.id-app-orig-desc").first().toString()
        .replace('<div class="id-app-orig-desc">', "").replace('<p>','').replace('</p>','')
        .replace("</div>",'').replace("<br>","\n");
        if(description == 'null'){
            description = htmlPage.select("div.details-section-body.expandable")
            .select("div.full-text.multicol").first().toString().replace("<p>", "\n")
        }
        def detailsInfo = htmlPage.select("div.details-info");
        def appName = detailsInfo.select("div.document-title").toString()
        .replace('<div class="document-title" itemprop="name">', '').replace('<div>','')
        .replace('</div>','') //App name
        def subCategory = Jsoup.parse(detailsInfo.select("span[itemprop=genre]").first().toString()
            .replace('<span itemprop="genre">','').replace('</span>','')).text()
        def appIcon = detailsInfo.select("img.cover-image").attr("src"); // App Icon url
        def string_BeforePrice = getIndexOfFirstDegit(detailsInfo.select("meta[itemprop=price]")
            .attr("content"))
        def appPrice = detailsInfo.select("meta[itemprop=price]").attr("content")
        .replace(string_BeforePrice,'') // App price
        def category = Jsoup.parse(detailsInfo.select("a.category").attr('href').toString()).text()
        int gameIndex = category.indexOf("GAME");
        if(gameIndex == -1){
            category = subCategory
        }else{
            category = 'GAMES'
        }
        appData.appBunddleID = appBunddleID
        appData.description = Jsoup.parse(description).text()
        appData.appName = Jsoup.parse(appName).text()
        appData.appIcon = appIcon
        appData.price = appPrice
        appData.category = category
        appData.subCategory = subCategory
        //log.debug'Category '+ Jsoup.parse(doc.select("a.category").toString()).text()
        return appData
    }
 // Remove Char before price

	def getIndexOfFirstDegit(String numericAlphabet){
		def strBeforeNumber = ''
		char[] charValue = numericAlphabet.toCharArray();
		for (int index = 0; index < charValue.length; index++) {
			if (Character.isDigit(charValue[index])) {
				return strBeforeNumber
			}
			strBeforeNumber =strBeforeNumber + charValue[index].toString()
		}
	}

 

The readAppInfoByAppUrl() method return the app info in Map.

 

THANKS

About Author

Author Image
Pankaj Kumar Yadav

Pankaj has been working as a Grails developer expertise in struts, spring, ejb, hibernate and angularjs framework.

Request for Proposal

Name is required

Comment is required

Sending message..