First, use standard JavaScript objects as optional parameters to construct Casperjs instance 1 directly inside the Create () function
var casper = require ( ' Casper '). Create ({clientscripts: [ ' includes/jquery.js ', //These TW o scripts would be injected in remote ' includes/underscore.js ' // DOM on every request], PageSettings: {loadimages: false, //the W Ebpage instance used by Casper would loadplugins: false //use These settings}, LogLevel: "info", //only "info" level messages Would be logged verbose: true //log messages would be printed off to the console});
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
2 dynamically added at run time
var casper = require(‘casper‘).create();casper.options.waitTimeout = 1000;
Second, the most basic API introduction 1. Start
- Prototype: Start (String url[, Function then])
- Description: Configure and start Casperjs, then open the URL, and then follow the steps later.
- Parameters:
- URL: The URL that needs to be opened.
- Then: Subsequent actions that need to be performed.
-
Instance:
2. Run
- Prototype: Run (FN oncomplete[, int time])
- Description: Perform all the steps, and you can perform a callback after all the steps have been executed.
- Parameters:
- OnComplete: Optional parameter, when all steps are completed after execution of the callback function. Note: If you use a callback function, be sure to call exit () inside the callback function for easy return. At the same time, the operation after exit () does not have any effect because it is returned from the callback function after calling exit ().
-
Instance:
3 Then
- Prototype: Then (Function then)
- Description: By providing a simple function, use the standard way to add a navigation function to the execution stack.
- Parameters:
- Function: Simple functions.
-
Instance:
Iii. Comprehensive Examples
Gets the HTTP response of the current access
-
Code:
var casper =Require' Casper '). Create (); Casper.start (function () {this.echo ( "HTTP Response Info:"); this.echo ( "--------------------------------------");}); Casper.then (function (response {require ( ' utils '). Dump (response);}); Casper.then (function () {this.echo ( "--------------------------------------"); this.echo (
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
-
Results:
Reprint: http://blog.csdn.net/Kandy_Ye/article/details/47355169
Casperjs API Introduction