@crawlee/playwright 4.0.0-beta.143 → 4.0.0-beta.145
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.
|
@@ -423,13 +423,19 @@ export class AdaptivePlaywrightCrawler extends BasicCrawler {
|
|
|
423
423
|
}
|
|
424
424
|
createLogProxy(log, logs) {
|
|
425
425
|
return new Proxy(log, {
|
|
426
|
-
get(target, propertyName
|
|
426
|
+
get(target, propertyName) {
|
|
427
427
|
if (proxyLogMethods.includes(propertyName)) {
|
|
428
428
|
return (...args) => {
|
|
429
429
|
logs.push([target, propertyName, ...args]);
|
|
430
430
|
};
|
|
431
431
|
}
|
|
432
|
-
|
|
432
|
+
const value = Reflect.get(target, propertyName, target);
|
|
433
|
+
// Bind non-intercepted methods to the target instance so private #-fields
|
|
434
|
+
// (e.g. BaseCrawleeLogger.#options, #warningsLogged) do not throw TypeError at runtime.
|
|
435
|
+
if (typeof value === 'function') {
|
|
436
|
+
return value.bind(target);
|
|
437
|
+
}
|
|
438
|
+
return value;
|
|
433
439
|
},
|
|
434
440
|
});
|
|
435
441
|
}
|
|
@@ -188,6 +188,7 @@ export declare class PlaywrightCrawler<ContextExtension = Dictionary<never>, Ext
|
|
|
188
188
|
logger: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
189
189
|
minConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
190
190
|
maxConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
191
|
+
initialConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
191
192
|
maxRequestsPerMinute: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
192
193
|
keepAlive: z.ZodOptional<z.ZodBoolean>;
|
|
193
194
|
statistics: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
@@ -248,6 +249,7 @@ export declare class PlaywrightCrawler<ContextExtension = Dictionary<never>, Ext
|
|
|
248
249
|
logger: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
249
250
|
minConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
250
251
|
maxConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
252
|
+
initialConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
251
253
|
maxRequestsPerMinute: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
252
254
|
keepAlive: z.ZodOptional<z.ZodBoolean>;
|
|
253
255
|
statistics: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
@@ -27,7 +27,6 @@ export interface IRenderingTypePredictor {
|
|
|
27
27
|
*/
|
|
28
28
|
export declare class RenderingTypePredictor implements IRenderingTypePredictor {
|
|
29
29
|
#private;
|
|
30
|
-
private state;
|
|
31
30
|
constructor({ detectionRatio, persistenceOptions }: RenderingTypePredictorOptions);
|
|
32
31
|
/**
|
|
33
32
|
* Initialize the predictor by restoring persisted state.
|
|
@@ -67,11 +67,10 @@ const stateCodec = z.codec(persistedState, predictorState, {
|
|
|
67
67
|
*/
|
|
68
68
|
export class RenderingTypePredictor {
|
|
69
69
|
#detectionRatio;
|
|
70
|
-
|
|
71
|
-
state;
|
|
70
|
+
#state;
|
|
72
71
|
constructor({ detectionRatio, persistenceOptions }) {
|
|
73
72
|
this.#detectionRatio = detectionRatio;
|
|
74
|
-
this
|
|
73
|
+
this.#state = new RecoverableState({
|
|
75
74
|
defaultState: () => stateCodec.decode({}),
|
|
76
75
|
// The codec validates in the decode direction, so it is a Standard Schema as-is; encoding needs a call.
|
|
77
76
|
deserialize: stateCodec,
|
|
@@ -85,13 +84,13 @@ export class RenderingTypePredictor {
|
|
|
85
84
|
* Initialize the predictor by restoring persisted state.
|
|
86
85
|
*/
|
|
87
86
|
async initialize() {
|
|
88
|
-
await this
|
|
87
|
+
await this.#state.initialize();
|
|
89
88
|
}
|
|
90
89
|
/**
|
|
91
90
|
* Stop persisting the model, writing it out one last time. `initialize()` reopens the persistence window.
|
|
92
91
|
*/
|
|
93
92
|
async teardown() {
|
|
94
|
-
await this
|
|
93
|
+
await this.#state.teardown();
|
|
95
94
|
}
|
|
96
95
|
async [Symbol.asyncDispose]() {
|
|
97
96
|
await this.teardown();
|
|
@@ -100,7 +99,7 @@ export class RenderingTypePredictor {
|
|
|
100
99
|
* Predict the rendering type for a given URL and request label.
|
|
101
100
|
*/
|
|
102
101
|
predict({ url, loadedUrl, label }) {
|
|
103
|
-
const { logreg } = this
|
|
102
|
+
const { logreg } = this.#state.currentValue;
|
|
104
103
|
if (logreg.classifiers.length === 0) {
|
|
105
104
|
return { renderingType: 'clientOnly', detectionProbabilityRecommendation: 1 };
|
|
106
105
|
}
|
|
@@ -119,7 +118,7 @@ export class RenderingTypePredictor {
|
|
|
119
118
|
* Store the rendering type for a given URL and request label. This updates the underlying prediction model, which may be costly.
|
|
120
119
|
*/
|
|
121
120
|
storeResult(requests, renderingType) {
|
|
122
|
-
const state = this
|
|
121
|
+
const state = this.#state.currentValue;
|
|
123
122
|
for (const { url, loadedUrl, label } of Array.isArray(requests) ? requests : [requests]) {
|
|
124
123
|
const resultUrl = new URL(loadedUrl ?? url);
|
|
125
124
|
if (!state.detectionResults.has(renderingType)) {
|
|
@@ -133,14 +132,14 @@ export class RenderingTypePredictor {
|
|
|
133
132
|
this.retrain();
|
|
134
133
|
}
|
|
135
134
|
resultCount(label) {
|
|
136
|
-
return Array.from(this
|
|
135
|
+
return Array.from(this.#state.currentValue.detectionResults.values())
|
|
137
136
|
.map((results) => results.get(label)?.length ?? 0)
|
|
138
137
|
.reduce((acc, value) => acc + value, 0);
|
|
139
138
|
}
|
|
140
139
|
calculateFeatureVector(url, label) {
|
|
141
140
|
return [
|
|
142
|
-
mean((this
|
|
143
|
-
mean((this
|
|
141
|
+
mean((this.#state.currentValue.detectionResults.get('static')?.get(label) ?? []).map((otherUrl) => calculateUrlSimilarity(url, otherUrl) ?? 0)) ?? 0,
|
|
142
|
+
mean((this.#state.currentValue.detectionResults.get('clientOnly')?.get(label) ?? []).map((otherUrl) => calculateUrlSimilarity(url, otherUrl) ?? 0)) ?? 0,
|
|
144
143
|
];
|
|
145
144
|
}
|
|
146
145
|
retrain() {
|
|
@@ -149,7 +148,7 @@ export class RenderingTypePredictor {
|
|
|
149
148
|
[1, 0],
|
|
150
149
|
];
|
|
151
150
|
const Y = [0, 1];
|
|
152
|
-
for (const [renderingType, urlsByLabel] of this
|
|
151
|
+
for (const [renderingType, urlsByLabel] of this.#state.currentValue.detectionResults.entries()) {
|
|
153
152
|
for (const [label, urls] of urlsByLabel) {
|
|
154
153
|
for (const url of urls) {
|
|
155
154
|
X.push(this.calculateFeatureVector(url, label));
|
|
@@ -157,6 +156,6 @@ export class RenderingTypePredictor {
|
|
|
157
156
|
}
|
|
158
157
|
}
|
|
159
158
|
}
|
|
160
|
-
this
|
|
159
|
+
this.#state.currentValue.logreg.train(new Matrix(X), Matrix.columnVector(Y));
|
|
161
160
|
}
|
|
162
161
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlee/playwright",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.145",
|
|
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"
|
|
@@ -49,13 +49,13 @@
|
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@apify/datastructures": "^2.0.3",
|
|
51
51
|
"@apify/timeout": "^0.4.4",
|
|
52
|
-
"@crawlee/basic": "4.0.0-beta.
|
|
53
|
-
"@crawlee/browser": "4.0.0-beta.
|
|
54
|
-
"@crawlee/browser-pool": "4.0.0-beta.
|
|
55
|
-
"@crawlee/cheerio": "4.0.0-beta.
|
|
56
|
-
"@crawlee/core": "4.0.0-beta.
|
|
57
|
-
"@crawlee/types": "4.0.0-beta.
|
|
58
|
-
"@crawlee/utils": "4.0.0-beta.
|
|
52
|
+
"@crawlee/basic": "4.0.0-beta.145",
|
|
53
|
+
"@crawlee/browser": "4.0.0-beta.145",
|
|
54
|
+
"@crawlee/browser-pool": "4.0.0-beta.145",
|
|
55
|
+
"@crawlee/cheerio": "4.0.0-beta.145",
|
|
56
|
+
"@crawlee/core": "4.0.0-beta.145",
|
|
57
|
+
"@crawlee/types": "4.0.0-beta.145",
|
|
58
|
+
"@crawlee/utils": "4.0.0-beta.145",
|
|
59
59
|
"cheerio": "^1.0.0",
|
|
60
60
|
"jquery": "^3.7.1",
|
|
61
61
|
"ml-logistic-regression": "^2.0.0",
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
},
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "e8b4d50265b9e433ae61c69d16cc1fee00a4d7e9"
|
|
88
88
|
}
|