@crawlee/utils 4.0.0-beta.261 → 4.0.0-beta.262
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.
- package/internals/sitemap.js +52 -30
- package/package.json +4 -4
package/internals/sitemap.js
CHANGED
|
@@ -239,44 +239,66 @@ export async function* parseSitemap(initialSources, proxyUrl, options) {
|
|
|
239
239
|
// URL entries dropped by the enqueue strategy filter, reported in one warning per sitemap after
|
|
240
240
|
// the loop (per-entry warnings could flood the log; individual drops are logged at debug level).
|
|
241
241
|
let droppedUrlEntries = 0;
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
242
|
+
const iterator = items[Symbol.asyncIterator]();
|
|
243
|
+
try {
|
|
244
|
+
while (true) {
|
|
245
|
+
let next;
|
|
246
|
+
try {
|
|
247
|
+
next = await iterator.next();
|
|
247
248
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
logger?.warning(`Skipping nested sitemap ${item.url} (parent ${source.url}): ${reason}.`);
|
|
254
|
-
continue;
|
|
249
|
+
catch (e) {
|
|
250
|
+
// Parsing failed: give up on this sitemap, keep the others.
|
|
251
|
+
// Raw sources already logged the error in their pipeline callback.
|
|
252
|
+
if (source.type !== 'raw') {
|
|
253
|
+
logger?.warning(`Malformed sitemap content: ${source.url} (${e})`);
|
|
255
254
|
}
|
|
255
|
+
break;
|
|
256
256
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
// Keep only URL entries that match the enqueue strategy relative to the parent (see above).
|
|
264
|
-
if (source.type === 'url') {
|
|
265
|
-
const { allowed, reason } = filterUrl(item.loc, sitemapUrl, enqueueStrategy);
|
|
266
|
-
if (!allowed) {
|
|
267
|
-
droppedUrlEntries++;
|
|
268
|
-
logger?.debug(`Skipping sitemap URL ${item.loc} (parent ${source.url}): ${reason}.`);
|
|
257
|
+
if (next.done)
|
|
258
|
+
break;
|
|
259
|
+
const item = next.value;
|
|
260
|
+
if (item.type === 'sitemapUrl' && !visitedSitemapUrls.has(item.url)) {
|
|
261
|
+
if (nestedSitemapFilter && !nestedSitemapFilter(item.url)) {
|
|
262
|
+
logger?.debug(`Skipping sitemap ${item.url} due to nestedSitemapFilter.`);
|
|
269
263
|
continue;
|
|
270
264
|
}
|
|
265
|
+
// Keep only nested sitemaps matching the strategy (and using http(s)) relative to the
|
|
266
|
+
// parent. Raw string sources have no parent URL, so the check is skipped.
|
|
267
|
+
if (source.type === 'url') {
|
|
268
|
+
const { allowed, reason } = filterUrl(item.url, sitemapUrl, enqueueStrategy);
|
|
269
|
+
if (!allowed) {
|
|
270
|
+
logger?.warning(`Skipping nested sitemap ${item.url} (parent ${source.url}): ${reason}.`);
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
sources.push({ type: 'url', url: item.url, depth: (source.depth ?? 0) + 1 });
|
|
275
|
+
if (emitNestedSitemaps) {
|
|
276
|
+
yield { loc: item.url, originSitemapUrl: null };
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
if (item.type === 'url') {
|
|
280
|
+
// Keep only URL entries that match the enqueue strategy relative to the parent (see above).
|
|
281
|
+
if (source.type === 'url') {
|
|
282
|
+
const { allowed, reason } = filterUrl(item.loc, sitemapUrl, enqueueStrategy);
|
|
283
|
+
if (!allowed) {
|
|
284
|
+
droppedUrlEntries++;
|
|
285
|
+
logger?.debug(`Skipping sitemap URL ${item.loc} (parent ${source.url}): ${reason}.`);
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
yield {
|
|
290
|
+
...item,
|
|
291
|
+
originSitemapUrl: source.type === 'url'
|
|
292
|
+
? source.url
|
|
293
|
+
: `raw://${createHash('sha256').update(source.content).digest('base64')}`,
|
|
294
|
+
};
|
|
271
295
|
}
|
|
272
|
-
yield {
|
|
273
|
-
...item,
|
|
274
|
-
originSitemapUrl: source.type === 'url'
|
|
275
|
-
? source.url
|
|
276
|
-
: `raw://${createHash('sha256').update(source.content).digest('base64')}`,
|
|
277
|
-
};
|
|
278
296
|
}
|
|
279
297
|
}
|
|
298
|
+
finally {
|
|
299
|
+
// Mirrors `for await` cleanup: destroys the stream when we stop early or the consumer bails out.
|
|
300
|
+
await iterator.return?.();
|
|
301
|
+
}
|
|
280
302
|
if (droppedUrlEntries > 0 && source.type === 'url') {
|
|
281
303
|
logger?.warning(`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.`);
|
|
282
304
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlee/utils",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.262",
|
|
4
4
|
"description": "A set of shared utilities that can be used by crawlers",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.13.0"
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@apify/validations": "^1.1.2",
|
|
46
|
-
"@crawlee/http-client": "4.0.0-beta.
|
|
47
|
-
"@crawlee/types": "4.0.0-beta.
|
|
46
|
+
"@crawlee/http-client": "4.0.0-beta.262",
|
|
47
|
+
"@crawlee/types": "4.0.0-beta.262",
|
|
48
48
|
"@types/sax": "^1.2.7",
|
|
49
49
|
"cheerio": "^1.2.0",
|
|
50
50
|
"domhandler": "^6.0.1",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "56d3158b87fd8f83d195634092f6fbfe3b0e4616"
|
|
67
67
|
}
|