CasperJS script never exits

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 08:53:53

问题


My CasperJS script never stops executing.

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();

回答1:


It only looks as if CasperJS never exits. This is only an issue on windows. You probably see something like this:

C:\> casperjs script.js

C:\> Some script output
More script output
_

It has something to do with how CasperJS is installed and invoked. This happens usually when you have something like cygwin installed and then you install CasperJS through NPM. NPM will detect that you have cygwin and create a special batch file to start CasperJS with. There is somewhere a bug how that whole situation is handled, but it doesn't affect the functionality of CasperJS.

If you press Enter, you will see the prompt again:

C:\> casperjs script.js

C:\> Some script output
More script output

C:\> _

If you would use CasperJS from the master branch on GitHub, you would get a proper exe file which executes without those issues. See Installing from git. This has the advantage that you now can use PhantomJS 2, because it is not possible with the current release of version 1.1-beta3.




回答2:


Try adding exit on you run method.

casper.run(function() {
  this.exit();
});


来源:https://stackoverflow.com/questions/29392373/casperjs-script-never-exits

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!