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
fix: filter sitemap-derived URLs by enqueue strategy (#3797)
`SitemapRequestList`, `Sitemap.load` / `parseSitemap`, and
`RobotsTxtFile.getSitemaps()` now apply an enqueue strategy to the URLs
they extract. They keep only entries that match the strategy (default
`same-hostname`) relative to their parent sitemap, and always drop
non-`http(s)` schemes. This brings sitemap loading in line with
`enqueueLinks`, which already scopes discovered links to the same
hostname by default.
The selected strategy is also stamped onto the emitted `Request`
objects, so it keeps being enforced after navigation (e.g. across
redirects).
This changes the default behavior: cross-host sitemap entries are no
longer enqueued unless you opt in with `enqueueStrategy: 'all'` (or
`'same-domain'` / `'same-origin'`).
* Depending on the strategy you select, we will only check certain parts of the URLs found. Here is a diagram of each URL part and their name:
206
-
*
207
-
* ```md
208
-
* Protocol Domain
209
-
* ┌────┐ ┌─────────┐
210
-
* https://example.crawlee.dev/...
211
-
* │ └─────────────────┤
212
-
* │ Hostname │
213
-
* │ │
214
-
* └─────────────────────────┘
215
-
* Origin
216
-
*```
217
-
*
218
-
* - The `Protocol` is usually `http` or `https`
219
-
* - The `Domain` represents the path without any possible subdomains to a website. For example, `crawlee.dev` is the domain of `https://example.crawlee.dev/`
220
-
* - The `Hostname` is the full path to a website, including any subdomains. For example, `example.crawlee.dev` is the hostname of `https://example.crawlee.dev/`
221
-
* - The `Origin` is the combination of the `Protocol` and `Hostname`. For example, `https://example.crawlee.dev` is the origin of `https://example.crawlee.dev/`
222
-
*/
223
-
exportenumEnqueueStrategy{
224
-
/**
225
-
* Matches any URLs found
226
-
*/
227
-
All='all',
228
-
229
-
/**
230
-
* Matches any URLs that have the same hostname.
231
-
* For example, `https://wow.example.com/hello` will be matched for a base url of `https://wow.example.com/`, but
232
-
* `https://example.com/hello` will not be matched.
233
-
*
234
-
* > This strategy will match both `http` and `https` protocols regardless of the base URL protocol.
235
-
*/
236
-
SameHostname='same-hostname',
237
-
238
-
/**
239
-
* Matches any URLs that have the same domain as the base URL.
240
-
* For example, `https://wow.an.example.com` and `https://example.com` will both be matched for a base url of
241
-
* `https://example.com`.
242
-
*
243
-
* > This strategy will match both `http` and `https` protocols regardless of the base URL protocol.
244
-
*/
245
-
SameDomain='same-domain',
246
-
247
-
/**
248
-
* Matches any URLs that have the same hostname and protocol.
249
-
* For example, `https://wow.example.com/hello` will be matched for a base url of `https://wow.example.com/`, but
250
-
* `http://wow.example.com/hello` will not be matched.
251
-
*
252
-
* > This strategy will ensure the protocol of the base URL is the same as the protocol of the URL to be enqueued.
253
-
*/
254
-
SameOrigin='same-origin',
255
-
}
256
-
257
204
/**
258
205
* This function enqueues the urls provided to the {@apilink RequestQueue} provided. If you want to automatically find and enqueue links,
259
206
* you should use the context-aware `enqueueLinks` function provided on the crawler contexts.
`Skipped ${droppedUrlEntries} URL(s) from sitemap ${source.url} not matching enqueue strategy '${enqueueStrategy}' (or using a non-http(s) scheme). Enable debug logs to see each skipped URL.`,
0 commit comments