admin管理员组文章数量:1341457
I'm using CasperJS to evaluate a webpage. What I would like to do is to let me pass an argument that is a URL, have CasperJS download and evaluate the page, and output to standard out the webpage so I can use it in a BaSH script. Here is my code so far for Casper:
var casper = require('casper').create();
var url = casper.cli.args;
casper.start(url, function() {
this.evaluate(function() {
return document;
});
this.echo(this.getHTML());
});
casper.run();
This is what I'm seeing once I run it:
@:~/spider/casperjs$ casperjs viewsource.js google
CasperError: No steps defined, aborting
/usr/local/src/casperjs/modules/casper.js:1510 in run
~/spider/casperjs/viewsource.js:10
Help please.
I'm using CasperJS to evaluate a webpage. What I would like to do is to let me pass an argument that is a URL, have CasperJS download and evaluate the page, and output to standard out the webpage so I can use it in a BaSH script. Here is my code so far for Casper:
var casper = require('casper').create();
var url = casper.cli.args;
casper.start(url, function() {
this.evaluate(function() {
return document;
});
this.echo(this.getHTML());
});
casper.run();
This is what I'm seeing once I run it:
@:~/spider/casperjs$ casperjs viewsource.js google.
CasperError: No steps defined, aborting
/usr/local/src/casperjs/modules/casper.js:1510 in run
~/spider/casperjs/viewsource.js:10
Help please.
Share Improve this question edited Mar 24, 2014 at 8:27 Brice Favre 1,5171 gold badge17 silver badges36 bronze badges asked Mar 23, 2014 at 3:50 MoneyBagMoneyBag 1131 silver badge7 bronze badges 1- Possible duplicate of How to pass a variable to a CasperJS script through the mand line? – Ciro Santilli OurBigBook. Commented Nov 17, 2015 at 21:48
3 Answers
Reset to default 6If you want to name your argument :
mand :
casperjs viewsource.js --url="http://YourUrl."
script :
var mainUrl = casper.cli.get("url");
casper.start(mainUrl)
.then(......)
try this
var url = casper.cli.get(0)
I finally got it. here is the script:
var casper = require('casper').create();
var url = casper.cli.get(0);
casper.start(url, function () {
this.evaluate(function() {
return document;
});
this.echo(this.getHTML());
});
casper.run(function() {
this.exit();
});
本文标签: javascriptPass URL to CasperJS via CLIStack Overflow
版权声明:本文标题:javascript - Pass URL to CasperJS via CLI - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743643860a2515174.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论