2016-01-26 119 views
0

我想凑谷歌Play商店页面搜索完成后,所有动态添加的元素,即此一: https://play.google.com/store/search?q=stackoverflow&c=apps滚动看到DIV

正如你所看到的,新的应用程序加载时,您滚动到页面结尾,有时候还会出现“显示更多”按钮。我正在制作一个书签,它需要完成所有这些滚动操作,但是我无法完成它的工作。这是我当前的代码:

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是所有应用程序嵌套的div。

回答

0
var delay = 2000; 
var height = document.body.scrollHeight; 
window.scrollTo(0, document.body.scrollHeight); 
var interval = setInterval(function() { 

    window.scrollTo(0, document.body.scrollHeight); 

    if (document.getElementById('show-more-button') !== null) { 
     document.getElementById('show-more-button').click(); 
    } 
    if (height == document.body.scrollHeight) { 
     clearInterval(interval); 

     } 

    } else { 
     height = document.body.scrollHeight; 
    } 

}, delay);