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
myXCrawl is the crawler instance of the following example.
61
+
#### Example
62
62
63
63
```js
64
64
constmyXCrawl=newXCrawl({
@@ -72,7 +72,11 @@ const myXCrawl = new XCrawl({
72
72
})
73
73
```
74
74
75
-
#### About the pattern
75
+
Passing **baseConfig** is for **fetchHTML/fetchData/fetchFile** to use these values by default.
76
+
77
+
**Note:** To avoid repeated creation of instances in subsequent examples, **myXCrawl** here will be the crawler instance in the **fetchHTML/fetchData/fetchFile** example.
78
+
79
+
#### Mode
76
80
77
81
The mode option defaults to async .
78
82
@@ -81,27 +85,37 @@ The mode option defaults to async .
81
85
82
86
If there is an interval time set, it is necessary to wait for the interval time to end before sending the request.
83
87
88
+
#### IntervalTime
89
+
90
+
The intervalTime option defaults to undefined . If there is a setting value, it will wait for a period of time before requesting, which can prevent too much concurrency and avoid too much pressure on the server.
91
+
92
+
- number: The time that must wait before each request is fixed
93
+
- Object: Randomly select a value from max and min, which is more anthropomorphic
94
+
95
+
The first request is not to trigger the interval.
96
+
84
97
### fetchHTML
85
98
86
-
fetchHTML is the method of the above <a href="#myXCrawl" style="text-decoration: none">myXCrawl</a> instance, usually used to crawl HTML.
99
+
fetchHTML is the method of the above [myXCrawl](https://github.com/coder-hxl/x-crawl#Example-1) instance, usually used to crawl HTML.
fetchData is the method of the above <a href="#myXCrawl" style="text-decoration: none">myXCrawl</a> instance, which is usually used to crawl APIs to obtain JSON data and so on.
118
+
fetchData is the method of the above [myXCrawl](https://github.com/coder-hxl/x-crawl#Example-1) instance, which is usually used to crawl APIs to obtain JSON data and so on.
105
119
106
120
#### Type
107
121
@@ -120,15 +134,15 @@ const requestConifg = [
120
134
121
135
myXCrawl.fetchData({
122
136
requestConifg, // Request configuration, can be IRequestConfig | IRequestConfig[]
123
-
intervalTime:800//Interval between next requests, multiple requests are valid
137
+
intervalTime:{ max:5000, min:1000 } //The intervalTime passed in when not using myXCrawl
124
138
}).then(res=> {
125
139
console.log(res)
126
140
})
127
141
```
128
142
129
143
### fetchFile
130
144
131
-
fetchFile is the method of the above <a href="#myXCrawl" style="text-decoration: none">myXCrawl</a> instance, which is usually used to crawl files, such as pictures, pdf files, etc.
145
+
fetchFile is the method of the above [myXCrawl](https://github.com/coder-hxl/x-crawl#Example-1) instance, which is usually used to crawl files, such as pictures, pdf files, etc.
132
146
133
147
#### Type
134
148
@@ -157,23 +171,23 @@ myXCrawl.fetchFile({
157
171
158
172
## Types
159
173
160
-
- IAnyObject
174
+
#### IAnyObject
161
175
162
176
```ts
163
177
interface IAnyObject extendsObject {
164
178
[key: string | number | symbol]: any
165
179
}
166
180
```
167
181
168
-
- IMethod
182
+
#### IMethod
169
183
170
-
```ts
184
+
```ts
171
185
type IMethod ='get'|'GET'|'delete'|'DELETE'|'head'|'HEAD'|'options'|'OPTIONS'|'post'|'POST'|'put'|'PUT'|'patch'|'PATCH'|'purge'|'PURGE'|'link'|'LINK'|'unlink'|'UNLINK'
172
186
```
173
187
174
-
- IRequestConfig
188
+
#### IRequestConfig
175
189
176
-
```ts
190
+
```ts
177
191
interface IRequestConfig {
178
192
url: string
179
193
method?: IMethod
@@ -184,7 +198,7 @@ interface IRequestConfig {
184
198
}
185
199
```
186
200
187
-
- IIntervalTime
201
+
#### IIntervalTime
188
202
189
203
```ts
190
204
type IIntervalTime = number | {
@@ -193,7 +207,7 @@ type IIntervalTime = number | {
0 commit comments