从PHP脚本调用时,CasperJS在Cron中不起作用

时间:2015-08-27 15:29:06

标签: php cron phantomjs cpanel casperjs

作为测试,我有以下PHP sript:

<?php
  print shell_exec("/usr/local/bin/casperjs test.js --ssl-protocol=any --verbose");
?>

casperjs脚本如下:

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

casper.start('http://casperjs.org/', function() {
    this.echo(this.getTitle());
});

casper.thenOpen('http://phantomjs.org', function() {
    this.echo(this.getTitle());
});

casper.run();

我希望输出如下:

CasperJS, a navigation scripting and testing utility for PhantomJS and SlimerJS
PhantomJS | PhantomJS

这实际上在命令行中运行良好。但是,我需要运行一个在Cronjob中调用CasperJS脚本的PHP脚本。

PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs php /path/to/file/test.php

不知何故,当我这样做时,我收到以下错误:

File "/usr/local/bin/casperjs", line 138
except OSError as err:
                ^
SyntaxError: invalid syntax
X-Powered-By: PHP/5.4.21
Content-type: text/html

我曾尝试为PhantomJS设置环境变量,但它没有帮助。我将自己的脚本删除到上面,以确保此错误与我自己的编码无关。

有人知道如何让CasperJS从Cronjob中运行PHP脚本吗?

BTW:我使用的是CentOS。

1 个答案:

答案 0 :(得分:0)

我看到了同样的错误,因为我的机器安装了一些python版本。所以你应该安装python 2.6+或编辑var alertController : UIAlertController? func showAlert() { alertController = UIAlertController(title:"Example title", message: "Example description", preferredStyle: .Alert) let action1 = UIAlertAction(title: "Option 1", style: .Default) { (action : UIAlertAction) -> Void in //call to another method } // action2, action3, action4... let action5 = UIAlertAction(title: "Option 5", style: .Default) { (action : UIAlertAction) -> Void in //call to another method } let actionDismiss = UIAlertAction(title: "Dismiss", style: .Destructive) { (action : UIAlertAction) -> Void in self.alertController!.dismissViewControllerAnimated(true, completion: nil) } alertController!.addAction(action1) alertController!.addAction(action2) alertController!.addAction(action3) alertController!.addAction(action4) alertController!.addAction(action5) alertController!.addAction(actionDismiss) alertController!.preferredAction = action1 self.presentViewController(alertController!, animated: true, completion: nil) } override var preferredFocusedView: UIView? { if self.alertController != nil { return self.alertController!.preferredFocusedView } else { return self.collectionView } } 。感谢

/usr/local/bin/casperjs

OSError as err:

Python try...except comma vs 'as' in except