Scroll to see all dynamically added elements in div

I’m trying to scrape google play store page after search is done, i.e. this one: https://play.google.com/store/search?q=samsung&c=apps

As you can see, new apps load when you scroll to the end of page, and sometimes there appears an ‘Show more’ button also. I’m making an bookmarklet which needs to do all this scrolling, but I can’t make it work. This is my current code:

var appContainerDiv = document.getElementsByClassName("card-list two-cards")[0];
var numberOfApps = appContainerDiv.childNodes.length;

var numberOfApps2 = numberOfApps;

do {
    numberOfApps = numberOfApps2;
    window.scrollTo(0, document.body.scrollHeight);

    if (document.getElementById('show-more-button') !== null) {
        document.getElementById('show-more-button').click();
    }

    numberOfApps2 = document.getElementsByClassName("card-list two-cards")[0].childNodes.length;
}
while (numberOfApps2 > numberOfApps);

appContainerDiv is div in which all apps are nested.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.