当前位置:首页 > Windows程序 > 正文

[CasperJS] API--The casper module(译)

2021-03-28 Windows程序

ps:原谅我的渣渣英语

1、create()创建一个casper实例

var casper = require('casper').create();

2、Casper.options 设置casper属性

1)clientScripts

Type: Array

Default: []

每一个被加载页面中的所有路径集合

A collection of script filepaths to include in every page loaded.

2)exitOnError

Type: Boolean

Default: true

脚本运行错误,是否exit

Sets if CasperJS must exit when an uncaught error has been thrown by the script.

3)httpStatusHandlers

Type: Object

Default: {}

请求页面返回状态运行JS对象中的方法

A javascript Object containing functions to call when a requested resource has a given HTTP status code. A dedicated sample is provided as an example.

4)logLevel

Type: String

Default: "error"

日志登记

Logging level (see the logging section for more information)

5)onAlert

Type: Function

Default: null

Signature: onAlert(String message)

JS中的alert()被触发时调用该方法

A function to be called when a javascript alert() is triggered

6)onDie

Type: Function

Default: null

Casper中的die()被调用时调用

Signature: onDie(Object Casper, String message, String status)

A function to be called when Casper#die() is called

7)onError

Type: Function

Default: null

Signature: onError(String msg, Array backtrace)

error等级的事件发生时调用

A function to be called when an error” level event occurs

8)onLoadError

Type: Function

Default: null

Signature: onLoadError(Object Casper, String casper.requestUrl, String status)

请求页面不能下载时调用

A function to be called when a requested resource cannot be loaded

9)onPageInitialized

Type: Function

Default: null

Signature: onPageInitialized(Object page)

请求页面初始化完成后调用

A function to be called after WebPage instance has been initialized

10)onResourceReceived

Type: Function

Default: null

Signature: onResourceReceived(Object resource)

作为PhantomjsWebPage#onResourceReceived() 回调的代理

Proxy method for PhantomJS’ WebPage#onResourceReceived() callback, but the current Casper instance is passed as first argument.

11)onResourceRequested

Type: Function

Default: null

作为PhantomjsWebPage#onResourceRequested()回调的代理

Proxy method for PhantomJS’ WebPage#onResourceRequested() callback, but the current Casper instance is passed as first argument.

12)onStepComplete

Type: Function

Default: null

Signature: onStepComplete(Object Casper, stepResult)

一个step方法完成时被调用

A function to be executed when a step function execution is finished.

13)onStepTimeout

Type: Function

Default: Function

Signature: onStepTimeout(Integer timeout, Integer stepNum)

一个step方法超时时调用

A function to be executed when a step function execution time exceeds the value of the stepTimeout option, if any has been set.

By default, on timeout the script will exit displaying an error, except in test environment where it will just add a failure to the suite results.

14)onTimeout

Type: Function

Default: Function

Signature: onTimeout(Integer timeout)

操作超时时被调用

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/68827.html