admin管理员组文章数量:1435859
UPDATE: I found the solution and I forgot to add
var casper = require('casper').create();
on the top.
The original question: I installed phantom js 1.9.2 and casper js 1.0.3. Additionally I copy and pasted the follwing sample script directly from the casper js tutorial page:
casper.start('/', function() {
var url = '/';
this.download(url, 'google_pany.html');
});
casper.run(function() {
this.echo('Done.').exit();
});
This is the output on my mac os lion:
bin Tom$ ./casperjs ../site_loader.js
2013-11-26 18:53:20.375 phantomjs[2136: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.
ReferenceError: Can't find variable: casper
../site_loader.js:1
Hint: you may want to use the `casperjs test` mand.
^C
I have to manually cancel it otherwise it will never stop. However running the suggested mand yields:
bin Tom$ ./casperjs test
2013-11-26 18:54:01.504 phantomjs[2137: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.
No test path passed, exiting.
What is not correct here?
UPDATE: I found the solution and I forgot to add
var casper = require('casper').create();
on the top.
The original question: I installed phantom js 1.9.2 and casper js 1.0.3. Additionally I copy and pasted the follwing sample script directly from the casper js tutorial page:
casper.start('http://www.google.fr/', function() {
var url = 'http://www.google.fr/intl/fr/about/corporate/pany/';
this.download(url, 'google_pany.html');
});
casper.run(function() {
this.echo('Done.').exit();
});
This is the output on my mac os lion:
bin Tom$ ./casperjs ../site_loader.js
2013-11-26 18:53:20.375 phantomjs[2136: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.
ReferenceError: Can't find variable: casper
../site_loader.js:1
Hint: you may want to use the `casperjs test` mand.
^C
I have to manually cancel it otherwise it will never stop. However running the suggested mand yields:
bin Tom$ ./casperjs test
2013-11-26 18:54:01.504 phantomjs[2137: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.
No test path passed, exiting.
What is not correct here?
Share Improve this question edited Nov 26, 2013 at 18:00 toom asked Nov 26, 2013 at 17:55 toomtoom 13.4k27 gold badges95 silver badges137 bronze badges 1-
The example is for version 1.1.0-dev If you update, you will need to remove the
var casper = require('casper').create();
, otherwise the program won't exit because thecasperjs test
mand will provide that call – hexid Commented Nov 26, 2013 at 18:03
1 Answer
Reset to default 4Very first of all, you need to create a casper instance to work with, then everything you have written will work!
// sample.js
var casper = require('casper').create();
casper.start('http://www.google.fr/', function() {
var url = 'http://www.google.fr/intl/fr/about/corporate/pany/';
this.download(url, 'google_pany.html');
});
casper.run(function() {
this.echo('Done.').exit();
});
Output:
C:\Users\hello\Desktop>caperjs sample.js
Done.
C:\Users\hello\Desktop>ls -alt
-rwx------ hello mkpasswd 91 Nov 28 09:11 google_pany.html
...
本文标签: javascriptSample Casper JS Script does not workStack Overflow
版权声明:本文标题:javascript - Sample Casper JS Script does not work - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745642343a2667932.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论