Phantomjs Casper JS:奇怪错误:状态=失败(HTTP 200)

Phantomjs Casper JS:奇怪错误:状态=失败(HTTP 200),phantomjs,casperjs,web-crawler,Phantomjs,Casperjs,Web Crawler,我正在尝试用casperjs/phantomjs加载以下网页 因此,我编写了以下简单的casper脚本: var casper = require('casper').create({ verbose: true, logLevel: "debug" }); if( casper.cli.args.length != 1 ) casper.echo('No URL as arguments given. Exiting.\n').exit(); var id = ca

我正在尝试用casperjs/phantomjs加载以下网页

因此,我编写了以下简单的casper脚本:

var casper = require('casper').create({
    verbose: true,
    logLevel: "debug"
});

if( casper.cli.args.length != 1 )
    casper.echo('No URL as arguments given. Exiting.\n').exit();

var id = casper.cli.args[0]
casper.start( 'http://m.10bet.com/#leage_panel#' + id, function() {
    casper.waitForResource("http://m.10bet.com/pagemethods.aspx/UpdateEvents", function() {
        this.echo(casper.getPageContent())
    }, function(){}, function(){}, 10000 );
});

casper.run(function() {
    this.echo('Done.').exit();
});
因此,我正在等待加载最后一个资源,在本例中为“”。我用chrome开发者工具检查了这一点。随后,我想在控制台上输出呈现的html

然而,在我看来,不是html,而是一个非常奇怪的错误:

solaris:js_loaders Tom$ casperjs 10bet_loader.js 10096 
2014-01-03 17:31:36.545 phantomjs[8733:130b] *** WARNING: Method userSpaceScaleFactor in class NSView is deprecated on 10.7 and later. It should not be used in new applications. Use convertRectToBacking: instead. 
[info] [phantom] Starting...
[info] [phantom] Running suite: 2 steps
[debug] [phantom] opening url: http://m.10bet.com/#leage_panel#10096, HTTP GET
[debug] [phantom] Navigation requested: url=http://m.10bet.com/#leage_panel#10096, type=Other, lock=true, isMainFrame=true
[debug] [phantom] url changed to "http://m.10bet.com/#leage_panel#10096"
[debug] [phantom] Navigation requested: url=http://m.10bet.com/#leage_panel#10096, type=Reload, lock=true, isMainFrame=true
[warning] [phantom] Loading resource failed with status=fail (HTTP 200): http://m.10bet.com/#leage_panel#10096
[debug] [phantom] Successfully injected Casper client-side utilities
[debug] [phantom] url changed to "http://m.10bet.com/#leage_panel#10096"
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step 2/2 http://m.10bet.com/#leage_panel#10096 (HTTP 200)
[info] [phantom] Step 2/2: done in 761ms.
[info] [phantom] Step 3/3 http://m.10bet.com/#leage_panel#10096 (HTTP 200)
[info] [phantom] Step 3/3: done in 771ms.
[warning] [phantom] Casper.waitFor() timeout
[info] [phantom] Done 3 steps in 790ms
Done.
solaris:js_loaders Tom$ 

从日志中可以看到,错误“加载资源失败,状态=失败(HTTP 200):”给出了HTTP 200 ok,但失败。最终,网页不会在控制台上加载或打印。所以我想知道这里出了什么问题?

您的参数在其他脚本中有效吗?我很好奇,因为文档显示参数是以这种方式引用的

casper.echo(casper.cli.has(0));
我想知道这是否就是问题所在

用法:

casperjs stackoverflow.js --idEvent=10096
代码:


是的,这种方法确实有效。您还可以从日志中看到,url是根据参数正确构造的。可能与此有关:顺便说一句,希望您在这么多个月后已经解决了这个问题:)
var casper = require('casper').create ({
  waitTimeout: 15000,
  stepTimeout: 15000,
  verbose: true,
  viewportSize: {
    width: 1024,
    height: 768
  },
  pageSettings: {
    "userAgent": 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.10 (KHTML, like Gecko) Chrome/23.0.1262.0 Safari/537.10',
    "loadImages": false,
    "loadPlugins": false,
    "webSecurityEnabled": false,
    "ignoreSslErrors": true
  },
  onWaitTimeout: function() {
    casper.echo('Wait TimeOut Occured');
  },
  onStepTimeout: function() {
    casper.echo('Step TimeOut Occured');
  }
});

//vars
var idEvent = casper.cli.get('idEvent');

// start
casper.start();

// check args
casper.then(function() {
  if (!idEvent) {
    //usage check
    this.echo('Invalid usage: Must supply Event Id');
    casper.exit();
  }
});

casper.thenOpen('http://m.10bet.com/#leage_panel#' + idEvent, function() {
  casper.waitForResource('http://m.10bet.com/pagemethods.aspx/UpdateEvents', function() {
  //casper.waitForSelector('#league_block', function() {
  }, function then() {    //selector found
    this.echo(casper.getPageContent());
    casper.exit();
  }, function timeout() { //selector not found
    this.echo("Timeout On Selector...Exiting").exit();
  });
});

// executes
casper.run();