Jquery 以编程方式滚动到页面底部
我想使用Ruby脚本以编程方式滚动到页面底部,因为该网页实现了无限滚动。我可以用mechanize做这个吗 尝试使用window.scrollBy()&window.scrollTo(),这可能会有所帮助以下代码将滚动到底部,即使文档高度是动态的Jquery 以编程方式滚动到页面底部,jquery,ruby,scroll,Jquery,Ruby,Scroll,我想使用Ruby脚本以编程方式滚动到页面底部,因为该网页实现了无限滚动。我可以用mechanize做这个吗 尝试使用window.scrollBy()&window.scrollTo(),这可能会有所帮助以下代码将滚动到底部,即使文档高度是动态的 const getDocHeight = function() { return Math.max( document.body.scrollHeight, document.documentElement.scrollHeight
const getDocHeight = function() {
return Math.max(
document.body.scrollHeight,
document.documentElement.scrollHeight,
document.body.offsetHeight,
document.documentElement.offsetHeight,
document.body.clientHeight,
document.documentElement.clientHeight
);
};
scrollToBottom = () => {
let maxHeight = getDocHeight();
window.scrollBy(0, maxHeight);
window.onscroll = function(ev) {
if (getDocHeight() > maxHeight) {
maxHeight = getDocHeight();
window.scrollBy(0, maxHeight);
}
};
};
scrollToBottom();
我不知道。。。。你能?您尝试了什么?我想这个Answer可以帮助您:通常使用滚动触发的AJAX调用来实现无限滚动。如果你发布了你想要抓取的网站的url,我可能会告诉你更多。