0

如果我们在没有 and 的情况下使用 casper--engine=slimerjscasper.scrollToBottom();不起作用casper.page.scrollPosition = {top: scrollHeight, left: 0};

我的意思是,如果我们只使用$ casperjs file.js它就行不通。但有了$ casperjs --engine=slimerjs file.js它就足够了。

有什么建议吗?也许我应该在命令行中使用一些东西?喜欢--webdriver?我试过--ssl-protocol=any了——它也没有帮助。或者也许我应该包含 JS 文件,例如page.includeJs('https://www.my-site.com/thisjsfile.min.js')

PS:我不相信它会有帮助,但这里是代码:

casper.then(function() {
  this.waitForSelector('#myselector', function() {
    this.open('http://www.my-site.com/messages');
    this.echo('Open messages Inbox');
  });
})
.then(function() {
  this.repeat(timesForCasperRepeat, function() {
    this.wait(5000, function() {
      scrollHeight = this.evaluate(function() {
          return document.body.scrollHeight;
      });
      this.echo('Scroll Height: ' + scrollHeight);
      this.scrollToBottom();
      this.echo('scrolling down', 'INFO_BAR');
    });
  }); 
}); 

即使我scrollToBottom()改为:

this.page.scrollPosition = {
    top: scrollHeight,
    left: 0
  };

我还包括了 Anrtjom 的处理错误事件,有一个链接

我有错误:

Error: ReferenceError: Can't find variable: ourvarname1
Error: ReferenceError: Can't find variable: jQuery
Error: ReferenceError: Can't find variable: ourvarname2
Error: ReferenceError: Can't find variable: ourvarname3
Error: TypeError: 'undefined' is not a function (evaluating 'RegExp.prototype.test.bind(/^(data|aria)-[a-z_][a-z\d_.\-]*$/)')
Console: Unsafe JavaScript attempt to access frame with URL http://www.my-site.com/messages from frame with URL http://ads.my-site.com/daisy?browser=windows_chrome&base=1&page=Mailbox&pageurl=%2fmessages&format=half_page&authid=1%2c0%2c1457605848%2c0xf290ca6243d86169%3beed7d0c7a540f963b5268452a4c95ac74793badc&cachebust=655998. Domains, protocols and ports must match.
4

1 回答 1

1

找到了解决方案,它对我有用,问题是 casperjs 使用旧版本的 phantomjs,所以对于 mac 用户只需转到安装 casperjs 的文件夹。对我来说是:/usr/local/Cellar/casperjs/。并找到带有 phantomjs: 的文件夹/usr/local/Cellar/casperjs/1.1-beta4/libexec/phantomjs并将其更改为从 phantomjs 网站下载的新文件夹。

我发现 casperjs 使用的是 1.9 版本,但当前的 phantomjs 是 2.1.1,只是将文件夹更改为新的,没有问题。

于 2016-03-12T07:03:50.220 回答