You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+30-32Lines changed: 30 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -96,48 +96,22 @@ var options = {
96
96
var scraper =yoloScraper.createScraper(options);
97
97
```
98
98
99
-
#### Returned scraper function
99
+
#### `options.paramsSchema`
100
100
101
-
To use your scraper function, pass the params of your scraping request, and a callback function.
102
-
103
-
```js
104
-
scraper(params, function (error, data) {
105
-
if (error) {
106
-
// handle the `error`
107
-
} else {
108
-
// do something with `data`
109
-
}
110
-
});
111
-
```
112
-
113
-
When a request error occurred, the callback `error` argument will be an instance of _Error_ and the `data` will be _null_.
114
-
115
-
##### Case `options.validateList = false`
116
-
117
-
When an validation error occurred, the callback `error` argument will be an instance of _ValidationError_ and the `data` will be _null_.
118
-
119
-
Otherwise, the `error` will be _null_ and `data` will be the returned value of `options.extract`.
120
-
121
-
122
-
##### Case `options.validateList = true`
123
-
124
-
When an validation errors occurred, the callback `error` argument will be an instance of _ListValidationError_, otherwise it will be _null_.
125
-
126
-
If the value returned by `options.extract` is not an Array, `error` will be an instance of _Error_.
127
-
128
-
The `data` always be an _Array_ that only contains the **valid** item returned by `options.extract`.
101
+
The [JSON schema](https://spacetelescope.github.io/understanding-json-schema/) that defines the shape of the accepted arguments passed to `options.request`. When invalid, an Error will be thrown.
129
102
103
+
Optional
130
104
131
105
#### `options.request = function(params)`
132
106
133
-
Function that takes the *same argument*passed to your scraper function. It returns the options to pass to the [request ](https://www.npmjs.com/package/request) module to make the request.
107
+
Function that takes the arguments passed to your scraper function and returns the options to pass to the [request ](https://www.npmjs.com/package/request) module to make the network request.
Function that takes [request](https://www.npmjs.com/package/request) response, the response body and a [cheerio](https://www.npmjs.com/package/cheerio) instance. It returns the extracted data you want.
114
+
Function that takes [request](https://www.npmjs.com/package/request) response, the response body (_String_) and a [cheerio](https://www.npmjs.com/package/cheerio) instance. It returns the extracted data you want.
141
115
142
116
**Required**
143
117
@@ -158,7 +132,7 @@ Optional, default: `{}`
158
132
159
133
#### `options.ajvOptions`
160
134
161
-
The option to pass to [ajv](https://www.npmjs.com/package/ajv) when it compiles the schema.
135
+
The option to pass to [ajv](https://www.npmjs.com/package/ajv) when it compiles the JSON schemas.
162
136
163
137
Optional, default: `{allErrors: true}` - It check all rules collecting all errors
164
138
@@ -170,6 +144,30 @@ Use this option to validate each item of the data extracted **individually**. Wh
170
144
Optional, default: `false`
171
145
172
146
147
+
#### scraper function
148
+
149
+
To use your scraper function, pass the params to send to `options.request`, and a callback function.
150
+
151
+
```js
152
+
scraper(params, function (error, data) {
153
+
if (error) {
154
+
// handle the `error`
155
+
} else {
156
+
// do something with `data`
157
+
}
158
+
});
159
+
```
160
+
161
+
##### callback(error, data)
162
+
163
+
- When a network request error occurred, the callback `error` argument will be an _Error_ and the `data` will be _null_.
164
+
165
+
- When `options.validateList = false` and a validation error occurred, `error` will be a _ValidationError_ and the `data` will be _null_. Otherwise, the `error` will be _null_ and `data` will be the returned value of `options.extract`.
166
+
167
+
- When `options.validateList = true` and a validation errors occurred, `error` will be a _ListValidationError_, otherwise it will be _null_. If the value returned by `options.extract` is not an Array, `error` will be an instance of _Error_. The `data` always be an _Array_ that only contains the **valid** item returned by `options.extract`. It's not because `error` is a _ListValidationError_ that there will be no `data`!
0 commit comments