[英]CasperJS does not work in Cron when called from PHP script
As a test, I have the following PHP sript: 作为测试,我有以下PHP代码:
<?php
print shell_exec("/usr/local/bin/casperjs test.js --ssl-protocol=any --verbose");
?>
The casperjs script is the following: 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();
I would expect an output like: 我期望输出如下:
CasperJS, a navigation scripting and testing utility for PhantomJS and SlimerJS PhantomJS | PhantomJS
This actually works fine in commandline. 这实际上在命令行中可以正常工作。 However, I need to run a PHP script that calls a CasperJS script in a Cronjob.
但是,我需要运行一个PHP脚本,该脚本在Cronjob中调用CasperJS脚本。
PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs php /path/to/file/test.php
Somehow, when I do that, I get the following error: 以某种方式,当我这样做时,出现以下错误:
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
I have tried to set the environment variable for PhantomJS, but it does not help. 我试图为PhantomJS设置环境变量,但这无济于事。 I stripped down my own script to the above to ensure that this error has nothing to do with my own coding.
我将自己的脚本简化为上述内容,以确保此错误与我自己的编码无关。
Anybody any idea how to get CasperJS working in a PHP script from a Cronjob? 有人知道如何从Cronjob使CasperJS在PHP脚本中工作吗?
BTW: I use CentOS. 顺便说一句:我使用CentOS。
I have seen the same error, because my machine has installed some versions of python. 我看到了相同的错误,因为我的机器已经安装了某些版本的python。 So you should install python 2.6+ or edit
/usr/local/bin/casperjs
. 因此,您应该安装python 2.6+或编辑
/usr/local/bin/casperjs
。 Thanks 谢谢
from 从
OSError as err:
to 至
OSError, err:
Python try...except comma vs 'as' in except Python try ... except逗号与'as'除外
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.