2016-01-26 117 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);