从脚本调用 CasperJS
Call CasperJS from a script
我目前 运行 来自 CLI 的 CasperJS 脚本,如下所示:
casperjs --ignore-ssl-errors=true --ssl-protocol=any scrape.js
.. 但要使整个过程自动化,我需要从另一个脚本调用它作为 module/function 并传递参数(关键字等)。所以想知道最好的方法是什么。
想通了。 Spooky!
var spooky = new Spooky({
casper: {
//configure casperjs here
}
}, function (err) {
// NODE CONTEXT
console.log('We in the Node context');
spooky.start('http://www.example.com
spooky.then(function() {
// CASPERJS CONTEXT
console.log('We in the CasperJS context');
this.emit('consoleWe can also emit events here.');
this.click('a#somelink });
spooky.then(function() {
// CASPERJS CONTEXT
var size = this.evaluate(function() {
// PAGE CONTEXT
console.log('....'); // DOES NOT GET PRINTED OUT
__utils__.echo('We in the Page context'); // Gets printed out
this.capture('screenshot.png');
var $selectsize = $('select#myselectlist option').size();
return $selectsize;
})
})
我目前 运行 来自 CLI 的 CasperJS 脚本,如下所示:
casperjs --ignore-ssl-errors=true --ssl-protocol=any scrape.js
.. 但要使整个过程自动化,我需要从另一个脚本调用它作为 module/function 并传递参数(关键字等)。所以想知道最好的方法是什么。
想通了。 Spooky!
var spooky = new Spooky({
casper: {
//configure casperjs here
}
}, function (err) {
// NODE CONTEXT
console.log('We in the Node context');
spooky.start('http://www.example.com
spooky.then(function() {
// CASPERJS CONTEXT
console.log('We in the CasperJS context');
this.emit('consoleWe can also emit events here.');
this.click('a#somelink });
spooky.then(function() {
// CASPERJS CONTEXT
var size = this.evaluate(function() {
// PAGE CONTEXT
console.log('....'); // DOES NOT GET PRINTED OUT
__utils__.echo('We in the Page context'); // Gets printed out
this.capture('screenshot.png');
var $selectsize = $('select#myselectlist option').size();
return $selectsize;
})
})