滚动查看 div 中所有动态添加的元素
Scroll to see all dynamically added elements in div
我正在尝试在搜索完成后抓取 google Play 商店页面,即这个页面:
https://play.google.com/store/search?q=Whosebug&c=apps
如您所见,当您滚动到页面末尾时会加载新应用,有时还会出现 'Show more' 按钮。我正在制作一个小书签,它需要进行所有这些滚动,但我无法让它工作。这是我当前的代码:
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,其中嵌套了所有应用程序。
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);
我正在尝试在搜索完成后抓取 google Play 商店页面,即这个页面: https://play.google.com/store/search?q=Whosebug&c=apps
如您所见,当您滚动到页面末尾时会加载新应用,有时还会出现 'Show more' 按钮。我正在制作一个小书签,它需要进行所有这些滚动,但我无法让它工作。这是我当前的代码:
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,其中嵌套了所有应用程序。
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);