phantomjs - CasperJS无法触发twitter无限滚动

标签 phantomjs infinite-scroll casperjs

我正在尝试使用 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/

相关文章:

infinite-scroll - 双向 react 虚拟化 InfiniteLoader,顶部和底部

windows - 使用cmd多窗口运行casperjs

windows - PhantomJS localstorage 和 WebSQL 在 Windows 上的什么位置?

r - 如何使用 rvest 在 R 中抓取这个网站?

javascript - Angular 2 : Enhance the performance of scroll event with a big ngFor List

ios - 重新加载数据时 TableView 闪烁

javascript - 如何检索CasperJS打开的最后一个页面的内容?

xpath - 所有 XPath 在 CasperJS 中都返回一个不存在的错误?

python - selenium.common.exceptions.WebDriverException : Message: 'Can not connect to GhostDriver'

javascript - 如何测试使用浏览器 API 的代码