@crawlee/basic 3.17.1-beta.79 → 3.17.1-beta.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -266,6 +266,9 @@ export interface BasicCrawlerOptions<Context extends CrawlingContext = BasicCraw
|
|
|
266
266
|
* 2. because they don't match enqueueLinks filters,
|
|
267
267
|
* 3. because they are redirected to a URL that doesn't match the enqueueLinks strategy,
|
|
268
268
|
* 4. or because the {@link BasicCrawlerOptions.maxRequestsPerCrawl|`maxRequestsPerCrawl`} limit has been reached
|
|
269
|
+
*
|
|
270
|
+
* When `enqueueLinks` is called with its own `onSkippedRequest` callback, both are invoked — this one first,
|
|
271
|
+
* then the `enqueueLinks` one.
|
|
269
272
|
*/
|
|
270
273
|
onSkippedRequest?: SkippedRequestCallback;
|
|
271
274
|
/** @internal */
|
|
@@ -636,8 +639,9 @@ export declare class BasicCrawler<Context extends CrawlingContext = BasicCrawlin
|
|
|
636
639
|
/**
|
|
637
640
|
* Wrapper around the crawling context's `enqueueLinks` method:
|
|
638
641
|
* - Injects `crawlDepth` to each request being added based on the crawling context request.
|
|
639
|
-
* -
|
|
640
|
-
*
|
|
642
|
+
* - Combines the `enqueueLinks` options with the crawler configuration - the user options take precedence,
|
|
643
|
+
* but the crawler limits are always enforced (the `limit` is capped by the remaining `maxRequestsPerCrawl`
|
|
644
|
+
* budget and skipped requests are always reported to the crawler too).
|
|
641
645
|
* @internal
|
|
642
646
|
*/
|
|
643
647
|
protected enqueueLinksWithCrawlDepth(options: SetRequired<EnqueueLinksOptions, 'urls'>, request: Request<Dictionary>, requestQueue: RequestProvider): Promise<BatchAddRequestsResult>;
|
|
@@ -1191,8 +1191,9 @@ class BasicCrawler {
|
|
|
1191
1191
|
/**
|
|
1192
1192
|
* Wrapper around the crawling context's `enqueueLinks` method:
|
|
1193
1193
|
* - Injects `crawlDepth` to each request being added based on the crawling context request.
|
|
1194
|
-
* -
|
|
1195
|
-
*
|
|
1194
|
+
* - Combines the `enqueueLinks` options with the crawler configuration - the user options take precedence,
|
|
1195
|
+
* but the crawler limits are always enforced (the `limit` is capped by the remaining `maxRequestsPerCrawl`
|
|
1196
|
+
* budget and skipped requests are always reported to the crawler too).
|
|
1196
1197
|
* @internal
|
|
1197
1198
|
*/
|
|
1198
1199
|
async enqueueLinksWithCrawlDepth(options, request, requestQueue) {
|
|
@@ -1206,29 +1207,34 @@ class BasicCrawler {
|
|
|
1206
1207
|
// Its return value is passed through as is, so a falsy one still skips the request.
|
|
1207
1208
|
return options.transformRequestFunction ? options.transformRequestFunction(newRequest) : newRequest;
|
|
1208
1209
|
};
|
|
1210
|
+
const limit = this.calculateEnqueuedRequestLimit(options.limit);
|
|
1209
1211
|
// Create a request-scoped callback that logs enqueueLimit once per request handler call
|
|
1210
1212
|
// Only log if an explicit limit was passed to enqueueLinks (not the internal maxRequestsPerCrawl-derived limit)
|
|
1211
1213
|
let loggedEnqueueLimitForThisRequest = false;
|
|
1212
1214
|
const onSkippedRequest = async (skippedOptions) => {
|
|
1213
1215
|
if (skippedOptions.reason === 'enqueueLimit') {
|
|
1214
1216
|
if (!loggedEnqueueLimitForThisRequest && options.limit !== undefined) {
|
|
1215
|
-
this.log.info(
|
|
1217
|
+
this.log.info(limit === options.limit
|
|
1218
|
+
? `Skipping URLs in the handler for ${request.url} due to the enqueueLinks limit of ${options.limit}.`
|
|
1219
|
+
: `Skipping URLs in the handler for ${request.url} due to the remaining maxRequestsPerCrawl budget of ${limit}, which is lower than the enqueueLinks limit of ${options.limit}.`);
|
|
1216
1220
|
loggedEnqueueLimitForThisRequest = true;
|
|
1217
1221
|
}
|
|
1218
1222
|
}
|
|
1219
1223
|
await this.handleSkippedRequest(skippedOptions);
|
|
1224
|
+
await options.onSkippedRequest?.(skippedOptions);
|
|
1220
1225
|
};
|
|
1221
1226
|
// `enqueueLinks` applies `options.label`/`options.userData` to every newly enqueued request, so a single
|
|
1222
1227
|
// validation against the label's schema covers them all (a no-op unless the router declares a schema).
|
|
1223
1228
|
await this.validateRequestUserData({ label: options.label, userData: options.userData });
|
|
1224
1229
|
return (0, core_1.enqueueLinks)({
|
|
1225
|
-
requestQueue,
|
|
1226
|
-
robotsTxtFile: await this.getRobotsTxtFileForUrl(request.url),
|
|
1227
|
-
respectRobotsTxtFile: this.respectRobotsTxtFile,
|
|
1228
|
-
onSkippedRequest,
|
|
1229
|
-
limit: this.calculateEnqueuedRequestLimit(options.limit),
|
|
1230
|
-
// Allow user options to override defaults set above ⤴
|
|
1231
1230
|
...options,
|
|
1231
|
+
// The options below are merged with the user options, so an explicitly `undefined` value
|
|
1232
|
+
// (e.g. `enqueueLinks({ urls, limit: config.limit })`) cannot discard the crawler defaults ⤵
|
|
1233
|
+
requestQueue: options.requestQueue ?? requestQueue,
|
|
1234
|
+
robotsTxtFile: options.robotsTxtFile ?? (await this.getRobotsTxtFileForUrl(request.url)),
|
|
1235
|
+
respectRobotsTxtFile: options.respectRobotsTxtFile ?? this.respectRobotsTxtFile,
|
|
1236
|
+
onSkippedRequest,
|
|
1237
|
+
limit,
|
|
1232
1238
|
transformRequestFunction: transformRequestFunctionWrapper,
|
|
1233
1239
|
});
|
|
1234
1240
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlee/basic",
|
|
3
|
-
"version": "3.17.1-beta.
|
|
3
|
+
"version": "3.17.1-beta.80",
|
|
4
4
|
"description": "The scalable web crawling and scraping library for JavaScript/Node.js. Enables development of data extraction and web automation jobs (not only) with headless Chrome and Puppeteer.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=16.0.0"
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
"@apify/log": "^2.4.0",
|
|
50
50
|
"@apify/timeout": "^0.4.0",
|
|
51
51
|
"@apify/utilities": "^2.7.10",
|
|
52
|
-
"@crawlee/core": "3.17.1-beta.
|
|
53
|
-
"@crawlee/types": "3.17.1-beta.
|
|
54
|
-
"@crawlee/utils": "3.17.1-beta.
|
|
52
|
+
"@crawlee/core": "3.17.1-beta.80",
|
|
53
|
+
"@crawlee/types": "3.17.1-beta.80",
|
|
54
|
+
"@crawlee/utils": "3.17.1-beta.80",
|
|
55
55
|
"csv-stringify": "^6.2.0",
|
|
56
56
|
"fs-extra": "^11.0.0",
|
|
57
57
|
"got-scraping": "^4.2.1",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "5b3c2d52f128643de6f515e87eeb531d55a187f0"
|
|
71
71
|
}
|