@crawlee/core 4.0.0-beta.149 → 4.0.0-beta.150
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.
|
@@ -139,7 +139,7 @@ export type EnqueueStrategyOption = EnqueueStrategy | 'all' | 'same-domain' | 's
|
|
|
139
139
|
* request domain, or a redirected one
|
|
140
140
|
* - In all other cases, we return the domain of the original request as that's the one we need to use for filtering
|
|
141
141
|
*/
|
|
142
|
-
export declare function resolveBaseUrlForEnqueueLinksFiltering({ enqueueStrategy, finalRequestUrl, originalRequestUrl, userProvidedBaseUrl, }: ResolveBaseUrl): string
|
|
142
|
+
export declare function resolveBaseUrlForEnqueueLinksFiltering({ enqueueStrategy, finalRequestUrl, originalRequestUrl, userProvidedBaseUrl, }: ResolveBaseUrl): string;
|
|
143
143
|
/**
|
|
144
144
|
* @internal
|
|
145
145
|
*/
|
|
@@ -21,15 +21,14 @@ export function resolveBaseUrlForEnqueueLinksFiltering({ enqueueStrategy, finalR
|
|
|
21
21
|
return finalUrlOrigin;
|
|
22
22
|
}
|
|
23
23
|
// If the user wants to ensure the same domain is accessed, regardless of subdomains, we check to ensure the domains match
|
|
24
|
-
//
|
|
25
|
-
// which is the intended behavior (since we went off domain)
|
|
24
|
+
// If they don't (we went off domain via a redirect), we keep filtering against the original domain - returning undefined would disable the filtering entirely
|
|
26
25
|
if (enqueueStrategy === EnqueueStrategy.SameDomain) {
|
|
27
26
|
const originalHostname = getDomain(originalUrlOrigin, { mixedInputs: false });
|
|
28
27
|
const finalHostname = getDomain(finalUrlOrigin, { mixedInputs: false });
|
|
29
28
|
if (originalHostname === finalHostname) {
|
|
30
29
|
return finalUrlOrigin;
|
|
31
30
|
}
|
|
32
|
-
return
|
|
31
|
+
return originalUrlOrigin;
|
|
33
32
|
}
|
|
34
33
|
// Always enqueue urls that are from the same origin in all other cases, as the filtering happens on the original request url, even if there was a redirect
|
|
35
34
|
// before actually finding the urls
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Awaitable, Dictionary } from '@crawlee/types';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import type { RequestOptions } from '../request.js';
|
|
3
|
+
import type { RequestOptions, Source } from '../request.js';
|
|
4
|
+
import { Request } from '../request.js';
|
|
4
5
|
import type { EnqueueStrategyOption } from './enqueue_links.js';
|
|
5
6
|
export interface UrlPatternObject {
|
|
6
7
|
glob?: string;
|
|
@@ -23,9 +24,16 @@ export type UrlPatternInput = GlobInput | RegExpInput;
|
|
|
23
24
|
export declare const urlPatternSchema: z.ZodType<UrlPatternInput>;
|
|
24
25
|
export type SkippedRequestReason = 'robotsTxt' | 'limit' | 'enqueueLimit' | 'filters' | 'transform' | 'redirect' | 'depth';
|
|
25
26
|
export type SkippedRequestCallback = (args: {
|
|
26
|
-
|
|
27
|
+
request: Request;
|
|
27
28
|
reason: SkippedRequestReason;
|
|
28
29
|
}) => Awaitable<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Builds the `{ request, reason }` argument passed to a {@link SkippedRequestCallback}, constructing the
|
|
32
|
+
* `Request` lazily on first access to `request` (and caching it) since most skips are never observed by a
|
|
33
|
+
* real callback and building a `Request` isn't free.
|
|
34
|
+
* @ignore
|
|
35
|
+
*/
|
|
36
|
+
export declare function createSkippedRequestArgs(source: string | Source, reason: SkippedRequestReason): Parameters<SkippedRequestCallback>[0];
|
|
29
37
|
/**
|
|
30
38
|
* @ignore
|
|
31
39
|
*/
|
|
@@ -58,7 +66,7 @@ export declare function constructUrlPatternObjects(patterns: readonly UrlPattern
|
|
|
58
66
|
* When `includePatterns` is empty/undefined, all options pass through (only exclude filtering applies).
|
|
59
67
|
* @ignore
|
|
60
68
|
*/
|
|
61
|
-
export declare function filterRequestOptionsByPatterns(requestOptions: RequestOptions[], includePatterns: UrlPatternObject[] | undefined, excludePatterns?: UrlPatternObject[], strategy?: EnqueueStrategyOption,
|
|
69
|
+
export declare function filterRequestOptionsByPatterns(requestOptions: RequestOptions[], includePatterns: UrlPatternObject[] | undefined, excludePatterns?: UrlPatternObject[], strategy?: EnqueueStrategyOption, onSkippedRequestOptions?: (options: RequestOptions) => void): RequestOptions[];
|
|
62
70
|
/**
|
|
63
71
|
* @ignore
|
|
64
72
|
*/
|
package/enqueue_links/shared.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { URL } from 'node:url';
|
|
2
2
|
import { Minimatch } from 'minimatch';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
+
import { Request } from '../request.js';
|
|
4
5
|
import { schemas } from '../validators.js';
|
|
5
6
|
const MAX_ENQUEUE_LINKS_CACHE_SIZE = 1000;
|
|
6
7
|
/**
|
|
@@ -19,6 +20,26 @@ export const urlPatternSchema = z.union([
|
|
|
19
20
|
schemas.objectWithKeys(['glob']),
|
|
20
21
|
schemas.objectWithKeys(['regexp']),
|
|
21
22
|
]);
|
|
23
|
+
/**
|
|
24
|
+
* Builds the `{ request, reason }` argument passed to a {@link SkippedRequestCallback}, constructing the
|
|
25
|
+
* `Request` lazily on first access to `request` (and caching it) since most skips are never observed by a
|
|
26
|
+
* real callback and building a `Request` isn't free.
|
|
27
|
+
* @ignore
|
|
28
|
+
*/
|
|
29
|
+
export function createSkippedRequestArgs(source, reason) {
|
|
30
|
+
const sourceReason = typeof source === 'string' ? undefined : source.skippedReason;
|
|
31
|
+
let request;
|
|
32
|
+
return {
|
|
33
|
+
reason: sourceReason ?? reason,
|
|
34
|
+
get request() {
|
|
35
|
+
request ??=
|
|
36
|
+
source instanceof Request
|
|
37
|
+
? source
|
|
38
|
+
: new Request(typeof source === 'string' ? { url: source } : source);
|
|
39
|
+
return request;
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
22
43
|
/**
|
|
23
44
|
* @ignore
|
|
24
45
|
*/
|
|
@@ -117,14 +138,14 @@ export function constructUrlPatternObjects(patterns) {
|
|
|
117
138
|
* When `includePatterns` is empty/undefined, all options pass through (only exclude filtering applies).
|
|
118
139
|
* @ignore
|
|
119
140
|
*/
|
|
120
|
-
export function filterRequestOptionsByPatterns(requestOptions, includePatterns, excludePatterns = [], strategy,
|
|
141
|
+
export function filterRequestOptionsByPatterns(requestOptions, includePatterns, excludePatterns = [], strategy, onSkippedRequestOptions) {
|
|
121
142
|
const excludeMatchers = excludePatterns.map(createPatternObjectMatcher);
|
|
122
143
|
const includeMatchers = includePatterns?.length ? includePatterns.map(createPatternObjectMatcher) : undefined;
|
|
123
144
|
return requestOptions
|
|
124
|
-
.filter((
|
|
125
|
-
const matchesExclude = excludeMatchers.some(({ match }) => match(url));
|
|
145
|
+
.filter((opts) => {
|
|
146
|
+
const matchesExclude = excludeMatchers.some(({ match }) => match(opts.url));
|
|
126
147
|
if (matchesExclude) {
|
|
127
|
-
|
|
148
|
+
onSkippedRequestOptions?.(opts);
|
|
128
149
|
}
|
|
129
150
|
return !matchesExclude;
|
|
130
151
|
})
|
|
@@ -138,7 +159,7 @@ export function filterRequestOptionsByPatterns(requestOptions, includePatterns,
|
|
|
138
159
|
}
|
|
139
160
|
}
|
|
140
161
|
// didn't match any positive pattern
|
|
141
|
-
|
|
162
|
+
onSkippedRequestOptions?.(opts);
|
|
142
163
|
return null;
|
|
143
164
|
})
|
|
144
165
|
.filter((opts) => opts !== null);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlee/core",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.150",
|
|
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": ">=22.0.0"
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"@apify/log": "^2.5.18",
|
|
53
53
|
"@apify/timeout": "^0.4.4",
|
|
54
54
|
"@apify/utilities": "^2.15.5",
|
|
55
|
-
"@crawlee/fs-storage": "4.0.0-beta.
|
|
56
|
-
"@crawlee/http-client": "4.0.0-beta.
|
|
57
|
-
"@crawlee/types": "4.0.0-beta.
|
|
58
|
-
"@crawlee/utils": "4.0.0-beta.
|
|
55
|
+
"@crawlee/fs-storage": "4.0.0-beta.150",
|
|
56
|
+
"@crawlee/http-client": "4.0.0-beta.150",
|
|
57
|
+
"@crawlee/types": "4.0.0-beta.150",
|
|
58
|
+
"@crawlee/utils": "4.0.0-beta.150",
|
|
59
59
|
"@sapphire/async-queue": "^1.5.5",
|
|
60
60
|
"@standard-schema/spec": "^1.0.0",
|
|
61
61
|
"@vladfrangu/async_event_emitter": "^2.4.6",
|
|
@@ -78,5 +78,5 @@
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
},
|
|
81
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "ef7e9fb2e2fcaa0f74e60a30fa8ae61c60c64626"
|
|
82
82
|
}
|