NoMore201 / googleplay-api

Google Play Unofficial Python API
Other
412 stars 208 forks source link

Unable to continue search on next page #123

Open kallix opened 4 years ago

kallix commented 4 years ago

Hi,

When using api.search(), the last child has a relatedLinks item that contains a nextPageUrl element with a link.

However, the api does not offer any way (that I know of) to follow this link.

Am I missing something ? Can something like that be implemented in googleplay-api ?

kallix commented 4 years ago

It seems that calling self.executeRequestApi2(FDFE + nextPageUrl) indeed gives some more results

adamaviv commented 4 years ago

This bit of code will collect all the apps and allow you continue on to the next page

from gpapi.googleplay import GooglePlayAPI
from gpapi import googleplay as gp
from gpapi import utils

api = GooglePlayAPI(...)
apps = []
result = api.search(<query>) #whatever the search query is
while result:
    for doc in result:
    if 'docid' in doc:
            sub_res.append(doc["docid"])
    for cluster in doc["child"]:
            for app in cluster["child"]:
                apps.append(app)
            if 'containerMetadata' in cluster and 'nextPageUrl' in cluster["containerMetadata"]:
                nextPageUrl = cluster["containerMetadata"]['nextPageUrl']
        response = api.executeRequestApi2(gp.FDFE + nextPageUrl)
                next_result = list(map(utils.parseProtobufObj,response.payload.listResponse.doc))
            else:
                next_result = None
    result = next_result

for app in apps: 
    print(apps["backendDocid'])

If I have time, I'll create a pull request for an option to get all the results in search()