我正在尝试使用 CasperJS 从 Twitter 获取一些信息。我被无限滚动困住了。问题是,即使使用 jquery 向下滚动页面似乎也不起作用。无论是滚动,还是触发 window
上的确切事件(像 uiNearTheBottom 一样)似乎都没有帮助。
有趣的是 - 当通过 FF 和 Chrome 中的 js 控制台注入(inject) JS 代码时,所有这些尝试都有效。
这是示例代码:
casper.thenEvaluate(function(){
$(window).trigger('uiNearTheBottom');
});
或
casper.thenEvaluate(function(){
document.body.scrollTop = document.body.scrollHeight;
});
最佳答案
如果 casper.scrollToBottom() 或 casper.scroll_to_bottom() 失败,那么下面的方法将为您服务:
this.page.scrollPosition = { top: this.page.scrollPosition["top"] + document.body.scrollHeight, left: 0 };
一个工作示例:
casper.start(url, function () {
this.wait(10000, function () {
this.page.scrollPosition = { top: this.page.scrollPosition["top"] + document.body.scrollHeight, left: 0 };
if (this.visible("div.load-more")) {
this.echo("I am here");
}
})});
它使用底层的 PhantomJS 滚动条 here
关于phantomjs - CasperJS无法触发twitter无限滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17521065/