CasperJS无法触发Twitter无限滚动 [英] CasperJS can not trigger twitter infinite scroll

查看:100
本文介绍了CasperJS无法触发Twitter无限滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 CasperJS 从Twitter获得一些信息.而且我陷入无限滚动.事实是,即使使用jquery向下滚动页面,也没什么用.滚动都没有,也没有触发window上的确切事件(类似于uiNearTheBottom之类)似乎都没有帮助. 有趣的事情-当通过FF&中的js控制台注入JS代码时,所有这些尝试都有效.铬合金. 这是示例代码:

I am trying to get some information from twitter using CasperJS. And I'm stuck with infinite scroll. The thing is that even using jquery to scroll the page down nothings seems to work. Neither scrolling, neither triggering the exact event on window (smth like uiNearTheBottom) doesn't seem to help. Interesting thing - all of these attempts work when injecting JS code via js console in FF & Chrome. Here's the example code :

casper.thenEvaluate(function(){
    $(window).trigger('uiNearTheBottom');
});

casper.thenEvaluate(function(){
    document.body.scrollTop  =  document.body.scrollHeight;
});

推荐答案

如果casper.scrollToBottom()无法使您或casper.scroll_to_bottom()失败,那么以下内容将为您服务:

If casper.scrollToBottom() fails you or casper.scroll_to_bottom(), then the one below will serve you:

this.page.scrollPosition = {顶部:this.page.scrollPosition [顶部"] + document.body.scrollHeight,左:0};

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");
    }
})});

它使用在此处

这篇关于CasperJS无法触发Twitter无限滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆