登录后的Casperjs/Pantomjs截屏

Casperjs/Phantomjs screencapture after login

本文关键字:Pantomjs 截屏 Casperjs 登录      更新时间:2023-09-26

我正在使用Casperjs/Pantomjs,在登录论坛网站后进行屏幕截图。我写的代码在cmd中给出了这个结果。

C:'xampp'htdocs'testing>casperjs screencappie.js
Var Declared
[info] [phantom] Starting...
Form FIlled
Clicked
Waited

我用运行代码

casperjs C:'path'path'..'test.js

我已经设置了所有的环境变量。它实际上遍历了所有的代码,但似乎没有做应该做的事情:制作屏幕截图。

我使用的代码:

var casper = require('casper').create({
    verbose: true,
    logLevel: 'debug'
});
var x       = require('casper').selectXPath;
var url     = 'http://forum.justforfun-gaming.com/newreply.php?tid=11178';
 console.log('Var Declared');
casper.start(url, function() {
   this.fill(x('//*[@id="content"]/table[2]/tbody/tr[2]/td/form'), {
        'username': 'USERNAME',
        'password': 'PASSWORD'
    }, true);
});
  console.log('Form FIlled');
casper.thenClick(x('//*[@id="content"]/table[2]/tbody/tr[2]/td/form/table/tbody/tr[4]/td/input'));
  console.log('Clicked');

casper.wait(5000, function() {
    this.capture('test.png', {
        top: 0,
        left: 0,
        width: 900,
        height: 900
    });
});
 console.log('Reached end of code');

调用casper.run();会运行整个步骤集,并在所有步骤完成后选择性地执行回调。显然,为了运行Casper导航套件,必须调用此方法。有关示例和更多信息,请阅读文档http://docs.casperjs.org/en/latest/index.html

你能试试这个吗?

casper.capture('yourImage.png');

而不是尝试调整大小。在尝试拍照之前,请确保你确实进入了屏幕捕捉的部分。

我遇到过这种情况,它只是默默地失败了,有时真的很头疼。