CasperJS脚本永远不会退出

Kun*_*615 3 windows cmd casperjs

我的CasperJS脚本永远不会停止执行.

var casper = require('casper').create();

casper.userAgent('Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36(KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36');

casper.start('https://www.google.co.in/',function(){    
  casper.wait(3000,function(){
    this.echo(this.getTitle());
  });
});
casper.run();
Run Code Online (Sandbox Code Playgroud)

Art*_* B. 6

它看起来好像CasperJS永远不会退出.这只是Windows上的一个问题.你可能会看到这样的事情:

C:\> casperjs script.js

C:\> Some script output
More script output
_
Run Code Online (Sandbox Code Playgroud)

它与CasperJS的安装和调用方式有关.这种情况通常发生在安装了cygwin,然后通过NPM安装CasperJS时.NPM会检测到你有cygwin并创建一个特殊的批处理文件来启动CasperJS.有一个错误是如何处理整个情况,但它不会影响CasperJS的功能.

如果按Enter键,您将再次看到提示:

C:\> casperjs script.js

C:\> Some script output
More script output

C:\> _
Run Code Online (Sandbox Code Playgroud)

如果您在GitHub上使用主分支中的CasperJS,您将获得一个正确的exe文件,该文件在没有这些问题的情况下执行.请参阅从git安装.这样做的好处是您现在可以使用PhantomJS 2,因为当前版本的1.1-beta3无法实现.