@crawlee/cli 4.0.0-beta.338 → 4.0.0-beta.339
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlee/cli",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.339",
|
|
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.13.0"
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@crawlee/templates": "4.0.0-beta.
|
|
48
|
+
"@crawlee/templates": "4.0.0-beta.339",
|
|
49
49
|
"@inquirer/prompts": "^8.8.1",
|
|
50
50
|
"ansi-colors": "^4.1.3",
|
|
51
51
|
"semver": "^7.8.5",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "9016ba5034c4a0ce279257baf476a609887fc604"
|
|
63
63
|
}
|
|
@@ -44,6 +44,7 @@ A passing type check does not cover these. Check each one against the project, t
|
|
|
44
44
|
- Navigation hooks share `navigationTimeoutSecs` with the navigation: "Navigation and the request handler are timed separately".
|
|
45
45
|
- HTTP crawlers and `sendRequest` use a different client: "The default HTTP client is now `impit`".
|
|
46
46
|
- Queue reuse: "Repeated `run()` calls no longer empty the request queue" and "Multiple crawler instances use separate default request queues".
|
|
47
|
+
- Several crawlers in one process each get their own `useState()` state: "Multiple crawler instances no longer share `useState()` state".
|
|
47
48
|
- `--omit=optional` in Dockerfiles and install scripts: "Installing with `--omit=optional` breaks native dependencies".
|
|
48
49
|
|
|
49
50
|
## Git
|
|
@@ -824,6 +824,52 @@ In v4, only the **first** crawler instance uses the default request queue. Each
|
|
|
824
824
|
|
|
825
825
|
If you explicitly pass a `requestQueue` (or `requestManager`) to the crawler, that queue is used as-is regardless of instance order.
|
|
826
826
|
|
|
827
|
+
### Multiple crawler instances no longer share `useState()` state
|
|
828
|
+
|
|
829
|
+
In v3, `crawler.useState()` and the `useState()` context helper of every crawler read and wrote the same `CRAWLEE_STATE` record, so two crawlers in one process shared a single state object.
|
|
830
|
+
|
|
831
|
+
In v4, each crawler has its own state, stored under `CRAWLEE_STATE_{id}`. The `{id}` is the crawler's `id` option. Without one, the crawler uses its creation index, such as `'0'`.
|
|
832
|
+
|
|
833
|
+
To share state between crawlers, use the standalone `useState()` function. It is not tied to a crawler, and every call with the same name returns the same auto-saved object:
|
|
834
|
+
|
|
835
|
+
```typescript
|
|
836
|
+
import { CheerioCrawler, PlaywrightCrawler, useState } from 'crawlee';
|
|
837
|
+
|
|
838
|
+
interface SharedState {
|
|
839
|
+
productUrls: string[];
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
const getSharedState = async () => useState<SharedState>('SHARED_STATE', { productUrls: [] });
|
|
843
|
+
|
|
844
|
+
const listingCrawler = new CheerioCrawler({
|
|
845
|
+
async requestHandler({ $ }) {
|
|
846
|
+
const state = await getSharedState();
|
|
847
|
+
|
|
848
|
+
for (const link of $('a.product').toArray()) {
|
|
849
|
+
state.productUrls.push(new URL($(link).attr('href')!, 'https://example.com').href);
|
|
850
|
+
}
|
|
851
|
+
},
|
|
852
|
+
});
|
|
853
|
+
|
|
854
|
+
const productCrawler = new PlaywrightCrawler({
|
|
855
|
+
async requestHandler({ request, page, pushData }) {
|
|
856
|
+
// The same object the listing crawler wrote to.
|
|
857
|
+
const state = await getSharedState();
|
|
858
|
+
|
|
859
|
+
await pushData({ url: request.url, title: await page.title(), productCount: state.productUrls.length });
|
|
860
|
+
},
|
|
861
|
+
});
|
|
862
|
+
|
|
863
|
+
await listingCrawler.run(['https://example.com/products']);
|
|
864
|
+
|
|
865
|
+
const { productUrls } = await getSharedState();
|
|
866
|
+
await productCrawler.run(productUrls);
|
|
867
|
+
```
|
|
868
|
+
|
|
869
|
+
Don't give two crawlers the same `id` to share state. They would get the same `useState()` object, but the `id` also names their statistics and session pool records, so the two crawlers would overwrite each other's.
|
|
870
|
+
|
|
871
|
+
A crawler without an `id` finds its state after a restart or an Actor migration only when the script creates its crawlers in the same order every time. If it runs more than one crawler, give each a stable `id`. Crawlee logs a warning when more than one crawler without an `id` calls `useState()`.
|
|
872
|
+
|
|
827
873
|
### Repeated `run()` calls no longer empty the request queue
|
|
828
874
|
|
|
829
875
|
In v3, calling `crawler.run()` again on the same instance dropped the default request queue and created a fresh one, so the same URLs were crawled again — but only for a queue actually named `default`, which the Apify platform's default queue is not, so on the platform the second run silently crawled nothing.
|
|
@@ -1204,6 +1250,7 @@ Crawlee keeps its internal state in the default key-value store. These records n
|
|
|
1204
1250
|
|
|
1205
1251
|
| Record | v3 key | v4 key |
|
|
1206
1252
|
| --- | --- | --- |
|
|
1253
|
+
| `crawler.useState()` | `CRAWLEE_STATE` | `CRAWLEE_STATE_{id}` |
|
|
1207
1254
|
| Crawler statistics | `SDK_CRAWLER_STATISTICS_{id}` | `CRAWLEE_CRAWLER_STATISTICS_{id}` |
|
|
1208
1255
|
| Session pool | `SDK_SESSION_POOL_STATE` | `CRAWLEE_SESSION_POOL_STATE_{id}` |
|
|
1209
1256
|
| Request list progress | `SDK_{name}-REQUEST_LIST_STATE` | `CRAWLEE_REQUEST_LIST_STATE_{name}` |
|
|
@@ -1211,6 +1258,8 @@ Crawlee keeps its internal state in the default key-value store. These records n
|
|
|
1211
1258
|
| Sitemap request loader | `SITEMAP_REQUEST_LIST_STATE` | `CRAWLEE_SITEMAP_REQUEST_LOADER_STATE` |
|
|
1212
1259
|
| Rendering type predictor | `rendering-type-predictor-state` | `CRAWLEE_RENDERING_TYPE_PREDICTOR_STATE_{id}` |
|
|
1213
1260
|
|
|
1261
|
+
The `{id}` of `crawler.useState()` is the crawler's `id` option, or its creation index without one - see [Multiple crawler instances no longer share `useState()` state](#multiple-crawler-instances-no-longer-share-usestate-state).
|
|
1262
|
+
|
|
1214
1263
|
A `persistStateKey` or `persistRequestsKey` you pass to `RequestList` is used as it is, without the `SDK_` prefix v3 added, so a v4 run doesn't find the v3 record under `SDK_{key}`. The `{id}` of the statistics, the session pool, the rendering type predictor and the `ThrottlingRequestManager` comes from their `id` option. Without one, each class numbers its instances in creation order. The ones a crawler creates take the crawler's `id` option when it is set. Adaptive crawlers no longer share one rendering type model. The `ThrottlingRequestManager` stores its domain list under `CRAWLEE_THROTTLED_DOMAINS_{id}` and opens its per-domain queues under the alias `throttled-{id}-{domain}`.
|
|
1215
1264
|
|
|
1216
1265
|
v4 doesn't read the v3 keys. Resuming a v3 crawl on v4 is not supported, so finish or discard in-flight crawls before upgrading.
|