@jayyuen66/dsh-scrapling 0.0.3 → 0.1.1
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/README.md +137 -57
- package/README.zh-CN.md +111 -47
- package/THIRD_PARTY_NOTICES.md +7 -7
- package/client.js +85 -36
- package/cordis.patch.yml +3 -3
- package/host.js +25 -18
- package/package.json +57 -48
- package/py/adapters.py +466 -166
- package/py/bridge.py +36 -2
- package/py/crawl.py +99 -6
- package/py/guard.py +5 -25
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ Measured on a page whose content exists only after JavaScript runs:
|
|
|
25
25
|
|
|
26
26
|
This plugin adds exactly three things dsh's built-in tools cannot do:
|
|
27
27
|
|
|
28
|
-
1. **Browser rendering** - JavaScript execution via
|
|
28
|
+
1. **Browser rendering** - JavaScript execution via patchright.
|
|
29
29
|
2. **Structured extraction** - CSS/XPath selection returning data, not a wall of Markdown.
|
|
30
30
|
3. **Self-healing selectors** - Scrapling's `adaptive` mode relocates an element after
|
|
31
31
|
the site's markup changes. Verified working: a selector that returns `None` after a
|
|
@@ -33,7 +33,7 @@ This plugin adds exactly three things dsh's built-in tools cannot do:
|
|
|
33
33
|
|
|
34
34
|
## Status
|
|
35
35
|
|
|
36
|
-
All
|
|
36
|
+
All thirteen tools (the session family counts as seven) are implemented, registered and
|
|
37
37
|
exercised by the test suite. Tools
|
|
38
38
|
are registered **conditionally**: the plugin probes what the environment can actually
|
|
39
39
|
do at startup and only registers tools that will work, so the model never burns a
|
|
@@ -43,10 +43,9 @@ turn on a tool that was guaranteed to fail.
|
|
|
43
43
|
|---|---|---|---|
|
|
44
44
|
| `scrapling_fetch` | `Fetcher` (curl_cffi) | no | safe; a write verb is serialised once `allowWriteMethods` is on (parallel writes are duplicate submissions) |
|
|
45
45
|
| `scrapling_extract` | `Selector` + CSS/XPath + `adaptive` | no | safe |
|
|
46
|
-
| `scrapling_render` | `
|
|
47
|
-
| `scrapling_capture_xhr` | `capture_xhr` | yes | serialised |
|
|
48
|
-
| `
|
|
49
|
-
| `scrapling_session_open` / `scrapling_session_fetch` / `scrapling_session_list` / `scrapling_session_close` | Scrapling session classes | depends | serialised |
|
|
46
|
+
| `scrapling_render` | `StealthySession` (patchright) | yes | serialised; the anti-detection switches (`solveCloudflare` / `hideCanvas` / `blockWebrtc`) live here |
|
|
47
|
+
| `scrapling_capture_xhr` | `capture_xhr` (session-level recording) | yes | serialised |
|
|
48
|
+
| `scrapling_session_open` / `scrapling_session_fetch` / `scrapling_session_network` / `scrapling_session_state_save` / `scrapling_session_state_load` / `scrapling_session_list` / `scrapling_session_close` | Scrapling session classes | depends | serialised |
|
|
50
49
|
| `scrapling_crawl` | Scrapling Spider framework | no | serialised, runs as a job |
|
|
51
50
|
| `scrapling_answer` | any of the above, plus `ctx.llm` | no (yes with `render:true`) | serialised |
|
|
52
51
|
|
|
@@ -70,22 +69,25 @@ would throw all of that away.
|
|
|
70
69
|
minutes, a tool call has a timeout. Watch it with `job_list`, read it with
|
|
71
70
|
`job_output`, stop it with `job_kill`. A crawl also has a wall-clock ceiling
|
|
72
71
|
(`crawlMaxRuntimeSeconds`) and never leaves the start domain. Politeness is the
|
|
73
|
-
deployment's call, stated in the open:
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
deployment's call, stated in the open: it is configured through the deployment knobs
|
|
73
|
+
(`crawlRespectRobots`, `crawlDownloadDelayMs`, `crawlConcurrentRequests`,
|
|
74
|
+
`crawlAutothrottle`, `crawlStrategy`, `crawlCheckpointDir`), and **their defaults keep
|
|
75
|
+
Scrapling's spider defaults** — robots.txt is **not** obeyed, per-domain delay is 0,
|
|
76
|
+
and up to 4 requests run in parallel. The crawl is confined to the start domain, so it
|
|
77
|
+
never fans out across unrelated sites; a target that needs gentler behaviour is a
|
|
78
|
+
deployment decision, not a per-call one.
|
|
78
79
|
|
|
79
80
|
## Requirements
|
|
80
81
|
|
|
81
|
-
- **Python 3.
|
|
82
|
+
- **Python 3.14+** with Scrapling installed, in the repo's `_env/.venv` or reachable via
|
|
83
|
+
`PATH` (or set `pythonBin`). The chosen interpreter is logged at load time.
|
|
82
84
|
- **Browser engines are entirely the user's responsibility.** The plugin does not
|
|
83
85
|
download anything. Without a browser it simply does not register the
|
|
84
86
|
browser-dependent tools, so the model never wastes a turn calling them.
|
|
85
87
|
|
|
86
88
|
```sh
|
|
87
|
-
pip install "scrapling[rag]>=0.
|
|
88
|
-
python -m
|
|
89
|
+
pip install "scrapling[rag]>=0.5,<0.6"
|
|
90
|
+
python -m patchright install chromium
|
|
89
91
|
```
|
|
90
92
|
|
|
91
93
|
> **Why `rag` and not `fetchers`?** `rag` is `fetchers` plus `markdownify`, and the
|
|
@@ -93,12 +95,26 @@ python -m playwright install chromium
|
|
|
93
95
|
> raises `ModuleNotFoundError` on the first fetch. The Python side then tells you exactly
|
|
94
96
|
> which package is missing.
|
|
95
97
|
|
|
96
|
-
> **Version range**: this plugin is developed and verified against Scrapling **0.
|
|
98
|
+
> **Version range**: this plugin is developed and verified against Scrapling **0.5**
|
|
97
99
|
> and depends on its `Convertor._strip_noise_tags` / `_sanitize_for_ai`, `Selector`,
|
|
98
100
|
> `Spider` and `SessionManager` interfaces. None of those are stable API surface, so the
|
|
99
|
-
> upper bound is pinned below `0.
|
|
101
|
+
> upper bound is pinned below `0.6`; outside the range the guards still run, but the
|
|
100
102
|
> anti-injection cleaning and the crawl path may not behave as documented.
|
|
101
103
|
|
|
104
|
+
> **What 0.5 breaks, and how this plugin follows it:**
|
|
105
|
+
> - **The browser backend is patchright only.** 0.5 removed the plain Playwright backend
|
|
106
|
+
> (`DynamicFetcher` / `DynamicSession`), so browser scraping is one code path. The old
|
|
107
|
+
> standalone `scrapling_stealth_fetch` is therefore **gone**: its anti-detection
|
|
108
|
+
> arguments now live on `scrapling_render`.
|
|
109
|
+
> - **`capture_xhr` became session-level recording.** A capture now records into a
|
|
110
|
+
> session, so this plugin adds `scrapling_session_network` to read what an open session
|
|
111
|
+
> has accumulated; `scrapling_capture_xhr` itself opens a throwaway session for one page.
|
|
112
|
+
> - **`extra_flags` is additive now, not replacing.** Upstream made `config.extra_flags`
|
|
113
|
+
> *stack on top of* the built-in anti-detection flags instead of replacing them, so the
|
|
114
|
+
> old "passing `extra_flags` silently wipes the whole stealth stack" invariant no longer
|
|
115
|
+
> holds. This plugin sends **no** `extra_flags` at all, and WebRTC leak protection is
|
|
116
|
+
> carried by the `block_webrtc` switch itself.
|
|
117
|
+
|
|
102
118
|
## Install
|
|
103
119
|
|
|
104
120
|
```sh
|
|
@@ -107,6 +123,11 @@ dsh plugin --profile web add @jayyuen66/dsh-scrapling
|
|
|
107
123
|
|
|
108
124
|
The plugin is also installable from the Web UI via **Sidebar -> Plugins -> Add plugin**.
|
|
109
125
|
|
|
126
|
+
|
|
127
|
+
## Shared version floor
|
|
128
|
+
|
|
129
|
+
This package inlines `@jayyuen66/dsh-plugin-shared` at build time, so the runtime bundle no longer imports it -- but the version resolved for the build must still export every name the sources use. A profile `overrides` pin lower than this package's declared `@jayyuen66/dsh-plugin-shared` version makes the build read a copy that lacks those names.
|
|
130
|
+
|
|
110
131
|
## Replacing the built-in `web_fetch` and `web_search`
|
|
111
132
|
|
|
112
133
|
The plugin registers itself as a **fetch provider** and a **search provider** on
|
|
@@ -119,18 +140,31 @@ instead of dsh's plain-HTTP implementation. The model still calls `web_fetch` /
|
|
|
119
140
|
> (`tool "X" is already registered`). Registering a same-named tool is therefore closed off;
|
|
120
141
|
> the `ctx.web` provider seam is the supported replacement channel.
|
|
121
142
|
|
|
122
|
-
|
|
143
|
+
**`provideWebFetch` and `provideWebSearch` are on by default**, so the plugin registers
|
|
144
|
+
both providers whenever the sidecar is up. That still does **not** take over the built-in
|
|
145
|
+
tools on its own: the deployment config has to name the provider.
|
|
123
146
|
|
|
124
|
-
1.
|
|
147
|
+
1. `provideWebFetch` / `provideWebSearch` stay at their default (`true`);
|
|
125
148
|
2. set `fetchProvider` / `searchProvider` to `"scrapling"` in the **deployment** config.
|
|
126
149
|
|
|
127
|
-
> **Why
|
|
128
|
-
>
|
|
129
|
-
>
|
|
150
|
+
> **Why step 2 is still required.** The base bundle sets `fetchProvider: http`, and an id
|
|
151
|
+
> that is configured **wins** over auto-selection — so merely having the provider
|
|
152
|
+
> registered does not displace anything. (And if two providers are usable with no id
|
|
153
|
+
> named, `ctx.web` yields `WEB_PROVIDER_AMBIGUOUS` and the tool becomes unavailable
|
|
154
|
+
> outright.)
|
|
155
|
+
|
|
156
|
+
Two consequences of pointing that deployment line at this plugin:
|
|
157
|
+
|
|
158
|
+
- **If the sidecar cannot start, the built-in `web_fetch` reports
|
|
159
|
+
`WEB_PROVIDER_CONFIGURED_UNAVAILABLE`** rather than quietly falling back to HTTP — the
|
|
160
|
+
configured provider is not available, and the tool says so.
|
|
161
|
+
- **If you later remove the plugin but leave the line in** the deployment config, the
|
|
162
|
+
built-in tools report `WEB_PROVIDER_CONFIGURED_MISSING` — the named provider is no
|
|
163
|
+
longer registered. Go back and remove `fetchProvider` / `searchProvider` too.
|
|
130
164
|
|
|
131
165
|
When `searchEndpoint` is empty the search provider's `available()` is `false` — a second
|
|
132
|
-
guard:
|
|
133
|
-
|
|
166
|
+
guard: `provideWebSearch` being on cannot displace the built-in `web_search` until an
|
|
167
|
+
endpoint is configured.
|
|
134
168
|
|
|
135
169
|
### Search + render in one call
|
|
136
170
|
|
|
@@ -141,7 +175,7 @@ header), so `web_search` is split in two:
|
|
|
141
175
|
expected to be SearXNG-compatible JSON: GET `<endpoint>?q=<query>&format=json` returning
|
|
142
176
|
`{"results": [{"url", "title", "content"}]}`. Any backend producing that shape works.
|
|
143
177
|
- **Reading** → this plugin's sidecar. The first `searchRenderTopN` results (3 by default)
|
|
144
|
-
are actually fetched and, when a browser is available, rendered through
|
|
178
|
+
are actually fetched and, when a browser is available, rendered through patchright. The
|
|
145
179
|
body lands in `content`, the URLs in `sources`.
|
|
146
180
|
|
|
147
181
|
One `web_search` call therefore yields both "which pages are relevant" and "what those
|
|
@@ -167,16 +201,26 @@ that field follows along.
|
|
|
167
201
|
|
|
168
202
|
Notable switches:
|
|
169
203
|
|
|
170
|
-
- `pythonBin` - interpreter name or absolute path; empty means `
|
|
204
|
+
- `pythonBin` - interpreter name or absolute path; empty means "the repo's `_env/.venv` when
|
|
205
|
+
it is executable, otherwise `python3` on `PATH`". Whichever one is chosen is logged.
|
|
171
206
|
- `fetchEnabled` / `extractEnabled` / `renderEnabled` / `captureXhrEnabled` /
|
|
172
|
-
`sessionEnabled` / `
|
|
173
|
-
|
|
174
|
-
|
|
207
|
+
`networkEnabled` / `sessionEnabled` / `sessionStateEnabled` / `crawlEnabled` /
|
|
208
|
+
`answerEnabled` - on by default.
|
|
209
|
+
`scrapling_crawl` needs a profile that ships a jobs backend; without one it fails
|
|
210
|
+
loudly (`JOBS_UNAVAILABLE`) rather than silently doing nothing. `sessionStateEnabled`
|
|
211
|
+
controls the `scrapling_session_state_save` / `scrapling_session_state_load` pair, and
|
|
212
|
+
those need a deployment-side `sessionStateDir` to be usable.
|
|
213
|
+
- `pierceShadow` - **off** by default: it merges the contents of open shadow roots into
|
|
214
|
+
the body. A page that hides its text in shadow DOM is invisible to a plain HTML read,
|
|
215
|
+
so this is the switch for those; the model can also override it per call on the
|
|
216
|
+
browser tools.
|
|
175
217
|
- `extractionType` - `markdown` (default), `html` or `text`. All three paths run the
|
|
176
218
|
same anti-injection cleaning; `html` additionally strips event-handler attributes
|
|
177
219
|
(`on*`, `srcdoc`, `formaction`) and `meta refresh`, so the result is **not**
|
|
178
220
|
byte-for-byte raw HTML.
|
|
179
|
-
- `*MaxOutputChars` - per-tool output caps.
|
|
221
|
+
- `*MaxOutputChars` - per-tool output caps. The host-side cap only governs what reaches
|
|
222
|
+
the model context; the sidecar clips first by `maxContentChars` (characters) and the
|
|
223
|
+
host then trims to a byte budget. `crawlMaxItems` is the deployment-side
|
|
180
224
|
ceiling over the model-supplied `maxPages`; an out-of-range `maxPages` (0, negative,
|
|
181
225
|
NaN) is passed through unchanged so the sidecar reports the parameter error rather
|
|
182
226
|
than this plugin silently clamping it into a legal-looking value.
|
|
@@ -199,10 +243,10 @@ Notable switches:
|
|
|
199
243
|
- `answerProvider` / `answerModel` / `answerMaxTokens` - the model `scrapling_answer`
|
|
200
244
|
routes to and the per-call token ceiling. Provider and model left empty mean "follow
|
|
201
245
|
the model the current session is already using"; `answerMaxTokens` caps the reply.
|
|
202
|
-
- `mainContentOnly` / `headless` / `networkIdle` / `
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
246
|
+
- `mainContentOnly` / `headless` / `networkIdle` / `waitSelectorState` / `dataDir` -
|
|
247
|
+
extraction scope, browser mode, the selector state a page must reach before it is read,
|
|
248
|
+
and the sidecar working directory. Each is documented at its declaration in
|
|
249
|
+
[`host.ts`](./host.ts).
|
|
206
250
|
- `sidecarHandshakeTimeoutMs` / `fetchTimeoutMs` / `sidecarGraceMs` - the budget for the
|
|
207
251
|
sidecar handshake, the per-call cooperative timeout (declared as the tools' `timeoutMs`), and
|
|
208
252
|
how long the client waits for the process to exit after that timeout before forcing it down.
|
|
@@ -233,12 +277,18 @@ Notable switches:
|
|
|
233
277
|
|
|
234
278
|
**Deployment-grade knobs** (not on the settings card; set them in the `config:` block of
|
|
235
279
|
`cordis.patch.yml`): `requestTimeoutSeconds`, `maxUrlLength`, `browserExecutablePath`,
|
|
236
|
-
`browserCdpUrl`, `
|
|
237
|
-
`
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
280
|
+
`browserCdpUrl`, `browserInitScript`, `browserRealChrome`, `browserDnsOverHttps`,
|
|
281
|
+
`recordRequests`, `maxRecordedRequests`, `sessionStateDir`, `crawlMaxRuntimeSeconds`,
|
|
282
|
+
`crawlRespectRobots`, `crawlDownloadDelayMs`, `crawlConcurrentRequests`,
|
|
283
|
+
`crawlAutothrottle`, `crawlStrategy`, `crawlCheckpointDir`, `searchEndpoint`,
|
|
284
|
+
`searchRenderTopN`, `allowWriteMethods` (default `false`). The browser pair
|
|
285
|
+
(`browserExecutablePath`, `browserCdpUrl`) and `browserInitScript` are strong
|
|
286
|
+
capabilities - they hand Chromium a file to execute and the browser to a debugger
|
|
287
|
+
endpoint - so they come only from deployment config and are unreachable from model input.
|
|
288
|
+
`allowWriteMethods` is off by default for the same kind of reason: it decides whether the
|
|
289
|
+
model may change state on a remote host. The crawler knobs and `sessionStateDir` are
|
|
290
|
+
deployment decisions too - see
|
|
291
|
+
[Sessions, network history and crawler etiquette](#sessions-network-history-and-crawler-etiquette).
|
|
242
292
|
|
|
243
293
|
> **Settings changes need a dsh restart.** The gate policy and the sidecar environment are
|
|
244
294
|
> snapshotted once when the plugin is applied; edits on the settings card take effect on the
|
|
@@ -247,9 +297,40 @@ for the same kind of reason: it decides whether the model may change state on a
|
|
|
247
297
|
Disabling a tool also removes its system-prompt guidance, so the model is never told
|
|
248
298
|
about a capability that is not registered. The guidance is re-read at each prompt
|
|
249
299
|
assembly against the tools that scope can actually see, so a machine without a browser
|
|
250
|
-
loses the render/
|
|
300
|
+
loses the render / capture_xhr lines, and a sidecar that never came up loses all of them -
|
|
251
301
|
advice to call a missing tool costs a round trip and a confusing `UNKNOWN_TOOL`.
|
|
252
302
|
|
|
303
|
+
## Sessions, network history and crawler etiquette
|
|
304
|
+
|
|
305
|
+
Scrapling 0.5 exposes a few capabilities that this plugin surfaces as tools, each with a
|
|
306
|
+
deployment knob beside it. The tools are on the settings card; the knobs are
|
|
307
|
+
deployment-only (the `config:` block of `cordis.patch.yml`).
|
|
308
|
+
|
|
309
|
+
- **Network history.** An open session can record the XHR/fetch requests it makes.
|
|
310
|
+
`recordRequests` is the deployment default, and the model can turn recording on for one
|
|
311
|
+
session with `recordNetwork` on `scrapling_session_open`. Read it back with
|
|
312
|
+
`scrapling_session_network` (`urlPattern` / `includeBody` / `networkLimit` /
|
|
313
|
+
`maxBodyChars`); `maxRecordedRequests` caps how many entries a session keeps. A session
|
|
314
|
+
that is not recording reports an error rather than an empty list.
|
|
315
|
+
- **Shadow DOM.** `pierceShadow` merges open shadow roots into the body (off by default);
|
|
316
|
+
the model can also override it per call on the browser tools.
|
|
317
|
+
- **Login state.** `sessionStateDir` points at a directory for Playwright-compatible
|
|
318
|
+
login-state files. `scrapling_session_state_save` / `scrapling_session_state_load` write
|
|
319
|
+
and read them; the model can only pass a **plain file name** (no path), so the directory
|
|
320
|
+
stays a deployment decision. Empty means the pair is disabled.
|
|
321
|
+
- **Crawler etiquette and order.** `crawlRespectRobots` (off by default) makes the spider
|
|
322
|
+
obey robots.txt; with it on, a domain whose robots.txt cannot be fetched is **blocked**
|
|
323
|
+
rather than assumed permitted. `crawlDownloadDelayMs` (`0`) sets the gap between
|
|
324
|
+
requests, `crawlConcurrentRequests` (`4`) the parallelism, `crawlAutothrottle` (off) lets
|
|
325
|
+
the spider slow itself down, and `crawlStrategy` (`bfs` / `dfs`) picks breadth- or
|
|
326
|
+
depth-first.
|
|
327
|
+
- **Crawl checkpoints.** `crawlCheckpointDir` (empty) lets a crawl persist its queue, so a
|
|
328
|
+
restarted crawl resumes instead of going back to the start URL.
|
|
329
|
+
- **Browser extras.** `browserInitScript` injects a JS file into every page (a strong
|
|
330
|
+
capability), `browserRealChrome` uses the locally-installed Google Chrome instead of the
|
|
331
|
+
bundled Chromium, and `browserDnsOverHttps` routes the browser's DNS over HTTPS (useful
|
|
332
|
+
with a proxy to avoid DNS leaks).
|
|
333
|
+
|
|
253
334
|
## Proxies
|
|
254
335
|
|
|
255
336
|
Where a fetch goes out, resolved in this order - **first hit wins**:
|
|
@@ -276,7 +357,7 @@ connects directly no matter where the proxy came from.
|
|
|
276
357
|
What that looks like in practice - **with or without a proxy, the tools just work, with no
|
|
277
358
|
setting to fill in**:
|
|
278
359
|
|
|
279
|
-
| Your setup | Static fetching | Render /
|
|
360
|
+
| Your setup | Static fetching | Render / XHR |
|
|
280
361
|
| --- | --- | --- |
|
|
281
362
|
| No proxy | direct | direct |
|
|
282
363
|
| TUN mode (system-wide) | direct, forwarded by the TUN | same |
|
|
@@ -321,18 +402,16 @@ Details worth knowing:
|
|
|
321
402
|
(`intranet`, `router`) stay rejected.
|
|
322
403
|
- **WebRTC leaks are closed when proxied.** Chromium's WebRTC can send UDP around an
|
|
323
404
|
HTTP/SOCKS proxy, so one STUN call in a page is enough to learn the visitor's real exit
|
|
324
|
-
address.
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
itself is per page, not a session-wide history: upstream builds a fresh container for
|
|
335
|
-
every fetch, so five pages never replay page one's endpoints five times.
|
|
405
|
+
address. In 0.5 that protection is carried by the `block_webrtc` switch itself: this
|
|
406
|
+
plugin turns it on whenever a proxy is in play, and sends **no** `extra_flags` along the
|
|
407
|
+
way. (Before 0.5 it needed a pair of Chromium launch flags, because `config.extra_flags`
|
|
408
|
+
then **replaced** the anti-detection flags upstream computed; upstream made it additive,
|
|
409
|
+
so that workaround is gone with the old browser backend.)
|
|
410
|
+
- **Network history is session-level.** Recording is a construction-time setting
|
|
411
|
+
(`recordRequests` deployment default, or `recordNetwork` per `scrapling_session_open`),
|
|
412
|
+
and `scrapling_session_network` reads whatever the session accumulated across fetches.
|
|
413
|
+
`scrapling_capture_xhr`, by contrast, opens a throwaway session for one page and returns
|
|
414
|
+
the requests that page made.
|
|
336
415
|
- **`headers` and `retries` on `scrapling_session_fetch` are static-session only, and a
|
|
337
416
|
browser session says so.** Upstream reads neither for Playwright/patchright sessions
|
|
338
417
|
(request headers there are `extraHeaders`, retries is a construction-time setting) and
|
|
@@ -437,9 +516,9 @@ JSON endpoint.
|
|
|
437
516
|
written to the pipe. The `web_search` provider runs the same gate over the URLs it is
|
|
438
517
|
about to hand back: a hit the gate rejects never becomes a citeable source, so the model
|
|
439
518
|
is never offered an address the next fetch would refuse.
|
|
440
|
-
- **Browser engines ignore proxy environment variables.**
|
|
441
|
-
`HTTP_PROXY` / `HTTPS_PROXY`, so `scrapling_render`
|
|
442
|
-
|
|
519
|
+
- **Browser engines ignore proxy environment variables.** patchright does not read
|
|
520
|
+
`HTTP_PROXY` / `HTTPS_PROXY`, so `scrapling_render` and `scrapling_capture_xhr`
|
|
521
|
+
connect **directly** even when the rest of the system is
|
|
443
522
|
routed through a proxy — a browser-bound request leaves the tunnel. curl_cffi (behind
|
|
444
523
|
`scrapling_fetch` and the crawler) *does* honour those variables, so the two halves
|
|
445
524
|
behave differently on a proxy-bound network. This is stated rather than papered over:
|
|
@@ -448,7 +527,8 @@ JSON endpoint.
|
|
|
448
527
|
worse than saying so. `allowSyntheticDns` above only fixes the *gate*; it does not
|
|
449
528
|
change where traffic goes.
|
|
450
529
|
- **There are quotas; the resident resources are not unbounded.** At most 8 concurrent
|
|
451
|
-
sessions (of which at most 3 may be
|
|
530
|
+
sessions (of which at most 3 may be browser sessions — the `stealth` session type, each a
|
|
531
|
+
real Chromium process), at
|
|
452
532
|
most 2 crawls in flight, per-page bodies clipped at `maxContentChars`, 8 MB per protocol
|
|
453
533
|
frame, and 16 frames of pending queue. Hitting a ceiling yields a specific error code
|
|
454
534
|
(`SESSION_LIMIT` / `CRAWL_BUSY` / `BAD_FRAME`) the model can back off from, rather than
|
package/README.zh-CN.md
CHANGED
|
@@ -31,17 +31,16 @@ HTML 转 Markdown 用 turndown。作为默认档这没问题,但代价是:
|
|
|
31
31
|
|
|
32
32
|
## 当前状态
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
十三个工具(会话类算七个)全部实现、注册,并有测试覆盖。工具是**条件注册**的:插件启动时先探测运行环境
|
|
35
35
|
真正具备什么,只注册能用的 —— 模型不会浪费一轮去调用一个注定失败的工具。
|
|
36
36
|
|
|
37
37
|
| 工具 | 后端 | 需要浏览器 | 并发 |
|
|
38
38
|
|---|---|---|---|
|
|
39
39
|
| `scrapling_fetch` | `Fetcher`(curl_cffi) | 否 | 可并发;开了 `allowWriteMethods` 之后写动词转串行(并行写就是重复提交) |
|
|
40
40
|
| `scrapling_extract` | `Selector` + CSS/XPath + `adaptive` | 否 | 可并发 |
|
|
41
|
-
| `scrapling_render` | `
|
|
42
|
-
| `scrapling_capture_xhr` | `capture_xhr
|
|
43
|
-
| `
|
|
44
|
-
| `scrapling_session_open` / `scrapling_session_fetch` / `scrapling_session_list` / `scrapling_session_close` | Scrapling 会话类 | 看情况 | 串行 |
|
|
41
|
+
| `scrapling_render` | `StealthySession`(patchright) | 是 | 串行;反检测开关(`solveCloudflare` / `hideCanvas` / `blockWebrtc`)也在这一条上 |
|
|
42
|
+
| `scrapling_capture_xhr` | `capture_xhr`(会话级记录) | 是 | 串行 |
|
|
43
|
+
| `scrapling_session_open` / `scrapling_session_fetch` / `scrapling_session_network` / `scrapling_session_state_save` / `scrapling_session_state_load` / `scrapling_session_list` / `scrapling_session_close` | Scrapling 会话类 | 看情况 | 串行 |
|
|
45
44
|
| `scrapling_crawl` | Scrapling Spider 框架 | 否 | 串行,后台作业 |
|
|
46
45
|
| `scrapling_answer` | 上面任一抓取 + `ctx.llm` | 否(`render:true` 时是) | 串行 |
|
|
47
46
|
|
|
@@ -60,31 +59,45 @@ cookie,浏览器引擎要保留页面池,`adaptive` 要保留 SQLite 指纹
|
|
|
60
59
|
|
|
61
60
|
`scrapling_crawl` **立刻返回作业 id** 而不是阻塞:一次爬取是分钟级的,而工具调用有超时。
|
|
62
61
|
用 `job_list` 看进度、`job_output` 读结果、`job_kill` 中断。爬虫另有总时长上限
|
|
63
|
-
(`crawlMaxRuntimeSeconds
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
(`crawlMaxRuntimeSeconds`),且不会爬出起始域。礼貌性由部署方定夺,这里如实声明:它由部署级
|
|
63
|
+
旋钮配置(`crawlRespectRobots`、`crawlDownloadDelayMs`、`crawlConcurrentRequests`、
|
|
64
|
+
`crawlAutothrottle`、`crawlStrategy`、`crawlCheckpointDir`),而**它们的默认值沿用 Scrapling
|
|
65
|
+
spider 的默认值** —— **不遵守** robots.txt、每域延迟为 0、最多 4 个请求并发。爬取被锁在
|
|
66
|
+
起始域内,不会向无关站点扩散;需要更温和行为的站点是部署方的决定,而不是某次调用的参数。
|
|
67
67
|
|
|
68
68
|
## 环境要求
|
|
69
69
|
|
|
70
|
-
- **Python 3.
|
|
70
|
+
- **Python 3.14+**,装好 Scrapling —— 仓内 `_env/.venv` 里有、或能从 `PATH` 找到
|
|
71
|
+
(也可以设置 `pythonBin`)。插件装载时会把它选中的解释器写进日志。
|
|
71
72
|
- **浏览器完全由用户负责。** 插件不下载任何东西。没有浏览器时它只是不注册那些依赖
|
|
72
73
|
浏览器的工具,模型不会浪费一轮去调用它们。
|
|
73
74
|
|
|
74
75
|
```sh
|
|
75
|
-
pip install "scrapling[rag]>=0.
|
|
76
|
-
python -m
|
|
76
|
+
pip install "scrapling[rag]>=0.5,<0.6"
|
|
77
|
+
python -m patchright install chromium
|
|
77
78
|
```
|
|
78
79
|
|
|
79
80
|
> **为什么是 `rag` 而不是 `fetchers`?** `rag` 就是 `fetchers` 再加上 `markdownify`,而
|
|
80
81
|
> `extractionType` 默认就是 `markdown` —— 装成 `fetchers` 的话,第一次抓取就会在 Markdown
|
|
81
82
|
> 转换处抛 `ModuleNotFoundError`。Python 侧会明确告诉你是哪个包没装。
|
|
82
83
|
|
|
83
|
-
> **版本范围**:本插件在 Scrapling **0.
|
|
84
|
+
> **版本范围**:本插件在 Scrapling **0.5** 上开发与验证,并依赖它的
|
|
84
85
|
> `Convertor._strip_noise_tags` / `_sanitize_for_ai`、`Selector`、`Spider` 与
|
|
85
|
-
> `SessionManager` 这些接口。这些都还不是稳定 API 面,所以上界钉在 `0.
|
|
86
|
+
> `SessionManager` 这些接口。这些都还不是稳定 API 面,所以上界钉在 `0.6` 之前;装到
|
|
86
87
|
> 范围外时守卫会照常运行,但反注入清洗与爬虫链路可能不按预期。
|
|
87
88
|
|
|
89
|
+
> **0.5 破坏了什么,本插件怎么跟着走:**
|
|
90
|
+
> - **浏览器后端只剩 patchright。** 0.5 删掉了纯 Playwright 后端(`DynamicFetcher` /
|
|
91
|
+
> `DynamicSession`),浏览器抓取因此只剩一条代码路径。原来独立的 `scrapling_stealth_fetch`
|
|
92
|
+
> 随之**删除**:它的反检测参数现在都在 `scrapling_render` 上。
|
|
93
|
+
> - **`capture_xhr` 改成会话级记录。** 捕获现在记进会话,于是本插件新增
|
|
94
|
+
> `scrapling_session_network` 来读一个已开会话攒下的历史;`scrapling_capture_xhr` 自己为
|
|
95
|
+
> 单页起一个临时会话。
|
|
96
|
+
> - **`extra_flags` 现在是叠加而非替换。** 上游把 `config.extra_flags` 从「顶掉内建反检测
|
|
97
|
+
> flag」改成「叠加到它们之上」,所以过去那条「传了 `extra_flags` 整套 stealth 就没了」的
|
|
98
|
+
> 不变量不再成立。本插件**任何路径都不发** `extra_flags`,WebRTC 防泄露由 `block_webrtc`
|
|
99
|
+
> 开关本身承担。
|
|
100
|
+
|
|
88
101
|
## 安装
|
|
89
102
|
|
|
90
103
|
```sh
|
|
@@ -93,6 +106,11 @@ dsh plugin --profile web add @jayyuen66/dsh-scrapling
|
|
|
93
106
|
|
|
94
107
|
也可以在 Web 界面里 **Sidebar -> Plugins -> Add plugin** 安装。
|
|
95
108
|
|
|
109
|
+
|
|
110
|
+
## shared 的版本下限
|
|
111
|
+
|
|
112
|
+
本包在构建期就把 `@jayyuen66/dsh-plugin-shared` 内联进产物,运行期那份 bundle 不再 import 它——但构建时解析到的那份仍然必须导出源码用到的每个名字。profile 的 `overrides` 若把 `@jayyuen66/dsh-plugin-shared` 钉得低于本包声明的版本,构建读到的就是缺这些名字的一份产物。
|
|
113
|
+
|
|
96
114
|
## 替代 dsh 内置的 `web_fetch` 与 `web_search`
|
|
97
115
|
|
|
98
116
|
插件可以把自己注册成 `ctx.web` 的 **fetch provider** 与 **search provider**,于是内置的
|
|
@@ -103,17 +121,25 @@ dsh plugin --profile web add @jayyuen66/dsh-scrapling
|
|
|
103
121
|
> 重名会**抛错**(`tool "X" is already registered`)。所以同名注册工具这条路是封死的,
|
|
104
122
|
> `ctx.web` 的 provider 接缝是官方留的替换通道。
|
|
105
123
|
|
|
106
|
-
|
|
124
|
+
**`provideWebFetch` 与 `provideWebSearch` 默认就是开的**,所以只要 sidecar 起来了,两个
|
|
125
|
+
provider 都会被注册。但这**还不足以**真正接管内置工具:部署配置仍要点名。
|
|
107
126
|
|
|
108
|
-
1.
|
|
127
|
+
1. `provideWebFetch` / `provideWebSearch` 保持默认(`true`);
|
|
109
128
|
2. 在**部署配置**里把 `fetchProvider` / `searchProvider` 设为 `"scrapling"`。
|
|
110
129
|
|
|
111
|
-
>
|
|
112
|
-
>
|
|
113
|
-
>
|
|
130
|
+
> **为什么第 2 步仍然必须做。** base bundle 里写的是 `fetchProvider: http`,而**配了 id 就
|
|
131
|
+
> 以它为准**——所以仅仅「注册了 provider」并不会顶掉任何东西。(而且两个 provider 都可用、
|
|
132
|
+
> 又没点名时,`ctx.web` 会给出 `WEB_PROVIDER_AMBIGUOUS`,对应工具直接不可用。)
|
|
133
|
+
|
|
134
|
+
把那一行指向本插件之后,有两个反向风险要知道:
|
|
135
|
+
|
|
136
|
+
- **sidecar 起不来时,内置 `web_fetch` 会报 `WEB_PROVIDER_CONFIGURED_UNAVAILABLE`**,而不是
|
|
137
|
+
悄悄退回纯 HTTP——被配置的 provider 不可用,工具会如实报出来。
|
|
138
|
+
- **日后卸掉插件却留着那一行**,内置工具会报 `WEB_PROVIDER_CONFIGURED_MISSING`——点名的
|
|
139
|
+
provider 不再注册了。要回去把 `fetchProvider` / `searchProvider` 一并撤掉。
|
|
114
140
|
|
|
115
141
|
`searchEndpoint` 留空时 search provider 的 `available()` 为 false —— 这也是一道闸:光开
|
|
116
|
-
`provideWebSearch`
|
|
142
|
+
`provideWebSearch` 而没配端点,不会把内置 `web_search` 顶掉。
|
|
117
143
|
|
|
118
144
|
### 搜索 + 渲染一体化
|
|
119
145
|
|
|
@@ -144,14 +170,20 @@ Scrapling 的 Markdown 输出报成 `text`,内置渲染路径显示完全正
|
|
|
144
170
|
|
|
145
171
|
主要开关:
|
|
146
172
|
|
|
147
|
-
- `pythonBin` ——
|
|
173
|
+
- `pythonBin` —— 解释器名或绝对路径;留空表示「仓内 `_env/.venv` 可执行就用它,否则用
|
|
174
|
+
`PATH` 上的 `python3`」。选中哪一支会写进日志。
|
|
148
175
|
- `failFastOnMissingPython` —— 解释器不可用时直接**拒绝加载**(默认 `true`),而不是降级成
|
|
149
176
|
「所有工具不可用」:每个工具都要 sidecar,静默降级只会让模型在几轮之后才发现工具全都不见了。
|
|
150
177
|
设成 `false` 才走降级,附一条警告。
|
|
151
178
|
- `fetchEnabled` / `extractEnabled` / `renderEnabled` / `captureXhrEnabled` /
|
|
152
|
-
`sessionEnabled` / `
|
|
153
|
-
|
|
154
|
-
|
|
179
|
+
`networkEnabled` / `sessionEnabled` / `sessionStateEnabled` / `crawlEnabled` /
|
|
180
|
+
`answerEnabled` —— 默认开。`scrapling_crawl`
|
|
181
|
+
要求 profile 带作业后端;没有时它会当场报 `JOBS_UNAVAILABLE`,而不是静默地什么都不做。
|
|
182
|
+
`sessionStateEnabled` 管的是 `scrapling_session_state_save` /
|
|
183
|
+
`scrapling_session_state_load` 这一对,而它们要能可用还得部署侧配好 `sessionStateDir`。
|
|
184
|
+
- `pierceShadow` —— **默认关**:它把 open shadow root 的内容并进正文。页面把正文封进
|
|
185
|
+
shadow DOM 时,一段普通 HTML 读不到它,这一枚就是为那种页面准备的;模型也能在浏览器类
|
|
186
|
+
工具上按次覆盖。
|
|
155
187
|
- `extractionType` —— `markdown`(默认)/ `html` / `text`。三条路径都过同一套反注入
|
|
156
188
|
清洗;`html` 额外剥掉事件处理器属性(`on*`、`srcdoc`、`formaction`)与 `meta refresh`,
|
|
157
189
|
因此**拿到的不是字节级原始 HTML**。
|
|
@@ -164,8 +196,8 @@ Scrapling 的 Markdown 输出报成 `text`,内置渲染路径显示完全正
|
|
|
164
196
|
`socks5://127.0.0.1:7890`,可带 `user:pass@`。**留空表示跟随环境。** 它是部署级能力,
|
|
165
197
|
绝不进入任何工具 schema。判定顺序见下面的「代理」。
|
|
166
198
|
- `proxyBypass` —— 直连、不走代理的主机名,对应 `NO_PROXY`。
|
|
167
|
-
- `*MaxOutputChars` ——
|
|
168
|
-
|
|
199
|
+
- `*MaxOutputChars` —— 各工具的输出封顶。宿主侧的封顶只影响进模型上下文的那一段;
|
|
200
|
+
sidecar 侧先按 `maxContentChars`(字符)截一次,宿主再按字节预算收口。`crawlMaxItems` 是部署侧给模型可传的
|
|
169
201
|
`maxPages` 封的顶;越界的 `maxPages`(0、负数、NaN)**原样透传**,让 sidecar 报参数错误,
|
|
170
202
|
而不是由本插件悄悄夹成一个看起来合法的值。`crawlMaxRuntimeSeconds` 是爬虫的**墙上时钟**
|
|
171
203
|
上限:页数上限管不了一页等一分钟的站点,而爬虫是没人看的后台线程。到点由蜘蛛走引擎自己
|
|
@@ -184,25 +216,57 @@ Scrapling 的 Markdown 输出报成 `text`,内置渲染路径显示完全正
|
|
|
184
216
|
单次调用的协同超时(声明在各工具的 `timeoutMs` 上),以及超时之后客户端再等进程退出多久才
|
|
185
217
|
强制拆掉。三项都在设置卡上。`scrapling_crawl` 是例外:它作为作业运行且不传超时——一次爬取
|
|
186
218
|
是分钟级的,套一个固定预算会让每次成功都在最后一刻被判超时,然后整个进程被拆掉重来。
|
|
187
|
-
- `
|
|
188
|
-
|
|
189
|
-
|
|
219
|
+
- `blockAds` —— 默认开。它**叠在** SSRF 守卫之上而不是与它竞争:守卫最后注册(于是浏览器引擎
|
|
220
|
+
先跑它)并用 `route.fallback()` 放行,让 Scrapling 自己的拦截处理器仍然可达。
|
|
221
|
+
- `mainContentOnly` / `headless` / `networkIdle` / `waitSelectorState` / `dataDir` ——
|
|
222
|
+
抽取范围、浏览器模式、页面被读取前必须达到的选择器状态,以及 sidecar 的工作目录。
|
|
223
|
+
逐项说明见 [`host.ts`](./host.ts) 里的注释。
|
|
190
224
|
|
|
191
225
|
**部署级旋钮**(不在设置卡上,只走 [`cordis.patch.yml`](./cordis.patch.yml) 的 `config:`
|
|
192
226
|
块):`requestTimeoutSeconds`、`maxUrlLength`、`browserExecutablePath`、`browserCdpUrl`、
|
|
193
|
-
`
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
`allowWriteMethods`
|
|
227
|
+
`browserInitScript`、`browserRealChrome`、`browserDnsOverHttps`、`recordRequests`、
|
|
228
|
+
`maxRecordedRequests`、`sessionStateDir`、`crawlMaxRuntimeSeconds`、`crawlRespectRobots`、
|
|
229
|
+
`crawlDownloadDelayMs`、`crawlConcurrentRequests`、`crawlAutothrottle`、`crawlStrategy`、
|
|
230
|
+
`crawlCheckpointDir`、`searchEndpoint`、`searchRenderTopN`、`allowWriteMethods`(默认 `false`)。
|
|
231
|
+
其中 `browserExecutablePath`、`browserCdpUrl` 与 `browserInitScript` 是强能力 —— 它们等于让
|
|
232
|
+
Chromium 执行指定文件、把浏览器交给指定调试端点、或往每个页面注入一段 JS —— 所以只从部署配置来,
|
|
233
|
+
模型入参到不了。`allowWriteMethods` 同理:它决定模型能不能改对端的状态,因此默认关,也只从部署
|
|
234
|
+
配置来。爬虫那几枚与 `sessionStateDir` 同样是部署方的决定,见下面
|
|
235
|
+
[会话、网络历史与爬虫礼仪](#会话网络历史与爬虫礼仪)。
|
|
197
236
|
|
|
198
237
|
> **改完设置要重启 dsh。** 闸门策略与 sidecar 的环境变量都在插件 `apply()` 时取一次快照,
|
|
199
238
|
> 设置卡上的改动要等下次启动才生效。
|
|
200
239
|
|
|
201
240
|
关掉某个工具时,它的 system prompt 指引段**也一并消失**,
|
|
202
241
|
不会出现「工具没了但提示词还在」的割裂。指引每次装配都按「那个 scope 真看得见哪些工具」
|
|
203
|
-
现取,所以没装浏览器的机器会少掉 render/
|
|
242
|
+
现取,所以没装浏览器的机器会少掉 render / capture_xhr 那几句,sidecar 没起来的机器则一句都不说 ——
|
|
204
243
|
叫模型去调一个不存在的工具,代价是一轮往返加一个看不懂的 `UNKNOWN_TOOL`。
|
|
205
244
|
|
|
245
|
+
## 会话、网络历史与爬虫礼仪
|
|
246
|
+
|
|
247
|
+
Scrapling 0.5 放出几项能力,本插件把它们做成工具,每项旁边配一枚部署旋钮。工具在设置卡上,
|
|
248
|
+
旋钮只走部署配置([`cordis.patch.yml`](./cordis.patch.yml) 的 `config:` 块)。
|
|
249
|
+
|
|
250
|
+
- **网络历史。** 一个已开会话可以记录它发出的 XHR/fetch 请求。`recordRequests` 是部署级默认值,
|
|
251
|
+
模型可以在 `scrapling_session_open` 上用 `recordNetwork` 为这一个会话打开记录。用
|
|
252
|
+
`scrapling_session_network` 读回来(`urlPattern` / `includeBody` / `networkLimit` /
|
|
253
|
+
`maxBodyChars`);`maxRecordedRequests` 决定一个会话最多留多少条。没开记录的会话会**报错**,
|
|
254
|
+
而不是回一个空列表。
|
|
255
|
+
- **Shadow DOM。** `pierceShadow` 把 open shadow root 并进正文(默认关);模型也能在浏览器类
|
|
256
|
+
工具上按次覆盖。
|
|
257
|
+
- **登录态。** `sessionStateDir` 指向一个存放 Playwright 兼容登录态文件的目录。
|
|
258
|
+
`scrapling_session_state_save` / `scrapling_session_state_load` 一存一取;模型只能给一个
|
|
259
|
+
**纯文件名**(不能带路径),所以目录始终是部署方的决定。留空表示这对工具被禁用。
|
|
260
|
+
- **爬虫礼仪与顺序。** `crawlRespectRobots`(默认关)让蜘蛛遵守 robots.txt;打开后,取不到
|
|
261
|
+
robots.txt 的域会被**阻塞**,而不是当作允许。`crawlDownloadDelayMs`(`0`)是请求之间的间隔,
|
|
262
|
+
`crawlConcurrentRequests`(`4`)是并发数,`crawlAutothrottle`(关)让蜘蛛自行放慢,
|
|
263
|
+
`crawlStrategy`(`bfs` / `dfs`)选广度或深度优先。
|
|
264
|
+
- **断点续爬。** `crawlCheckpointDir`(空)让爬取把队列落盘,重启后从断点接着走,而不是回到
|
|
265
|
+
起始 URL 重跑。
|
|
266
|
+
- **浏览器附加项。** `browserInitScript` 往每个页面注入一段 JS(强能力),`browserRealChrome`
|
|
267
|
+
改用本机安装的 Google Chrome 而不是自带 Chromium,`browserDnsOverHttps` 让浏览器的 DNS 走
|
|
268
|
+
DoH(配代理时防 DNS 泄露)。
|
|
269
|
+
|
|
206
270
|
## 代理
|
|
207
271
|
|
|
208
272
|
抓取从哪儿出去,按这个顺序判定,**先命中先算**:
|
|
@@ -223,7 +287,7 @@ curl_cffi 对系统设置一无所知,不补这一档就会发现「浏览器
|
|
|
223
287
|
|
|
224
288
|
各环境下的实际表现 —— **开或不开代理,工具都直接可用,一行设置都不用填**:
|
|
225
289
|
|
|
226
|
-
| 你的环境 | 静态抓取 | 渲染 /
|
|
290
|
+
| 你的环境 | 静态抓取 | 渲染 / XHR |
|
|
227
291
|
| --- | --- | --- |
|
|
228
292
|
| 不开代理 | 直连 | 直连 |
|
|
229
293
|
| TUN 模式(系统层接管) | 直连,由 TUN 转发 | 同左 |
|
|
@@ -258,15 +322,14 @@ PAC 是唯一还需要手工填一次的形态:求值 PAC 要下载脚本并
|
|
|
258
322
|
需要代理才能访问。IP 字面量、本地能解析出来的私网答案、单标签主机名(`intranet`、`router`
|
|
259
323
|
这类)三条**照旧拒**。
|
|
260
324
|
- **走代理时会关掉 WebRTC 泄露。** Chromium 的 WebRTC 能绕过 HTTP/SOCKS 代理直接发 UDP,页面
|
|
261
|
-
里一句 STUN 就能问出访客的真实出口 IP。
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
flag
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
**逐页**的:上游每次 fetch 都新建一个收集容器,所以连着取五页不会把第一页的接口回五遍。
|
|
325
|
+
里一句 STUN 就能问出访客的真实出口 IP。0.5 起这道防护由 `block_webrtc` 开关本身承担:只要
|
|
326
|
+
有代理在,本插件就把它打开,一路上**不发**任何 `extra_flags`。(0.5 之前才需要往 Chromium
|
|
327
|
+
的启动参数里塞两条 flag,因为那时的 `config.extra_flags` 会**替换**上游自己算出的反检测
|
|
328
|
+
flag;上游改成叠加之后,那个绕法随旧浏览器后端一起消失。)
|
|
329
|
+
- **网络历史是会话级的。** 记录是构造期设置(部署默认 `recordRequests`,或每次
|
|
330
|
+
`scrapling_session_open` 上的 `recordNetwork`),`scrapling_session_network` 读的是这个会话
|
|
331
|
+
跨多次抓取攒下的历史。对比之下 `scrapling_capture_xhr` 为单页起一个临时会话,只回那一页发出
|
|
332
|
+
的请求。
|
|
270
333
|
- **`scrapling_session_fetch` 的 `headers` 与 `retries` 只属于 static 会话,给浏览器会话会直接报错。**
|
|
271
334
|
浏览器那侧的请求头是 `extraHeaders`,重试则是会话构造期的设置;上游对这两个键一声不吭地
|
|
272
335
|
丢掉,所以本包替它报错(`BAD_ARGS` 并点名该改用哪个旋钮)——「拧了没反应」正是这个插件要
|
|
@@ -346,14 +409,15 @@ PAC 是唯一还需要手工填一次的形态:求值 PAC 要下载脚本并
|
|
|
346
409
|
也对它准备交回的 URL 跑同一道闸门:被闸门判否的命中不会成为可引用的 source,模型因此不会
|
|
347
410
|
拿到一个「下一次抓取必然被拒」的地址。
|
|
348
411
|
|
|
349
|
-
- **浏览器引擎不认代理环境变量。**
|
|
350
|
-
`scrapling_render`
|
|
412
|
+
- **浏览器引擎不认代理环境变量。** patchright 不读 `HTTP_PROXY` / `HTTPS_PROXY`,所以
|
|
413
|
+
`scrapling_render` 与 `scrapling_capture_xhr` 即使在整台机器
|
|
351
414
|
都走代理时也**直连**——走浏览器的那部分请求会溜出隧道。而 `scrapling_fetch` 与爬虫底下的
|
|
352
415
|
curl_cffi **是**认这些变量的,于是两半在必须走代理的网络上行为不一致。这里写明而不是绕过去:
|
|
353
416
|
把浏览器也送进代理等于交给本包一项部署级强能力,而在没法对着一个真实代理验证的前提下
|
|
354
417
|
把它发出去,比说清楚更糟。上面的 `allowSyntheticDns` 只修闸门,**不改变流量去向**。
|
|
355
418
|
|
|
356
|
-
- **有配额,不是无上限的常驻资源。** 同开会话至多 8
|
|
419
|
+
- **有配额,不是无上限的常驻资源。** 同开会话至多 8 个(其中浏览器会话 —— 也就是 `stealth`
|
|
420
|
+
会话类型 —— 至多 3
|
|
357
421
|
个,每个都是一个真实的 Chromium 进程)、同时在跑的爬虫至多 2 个、单页正文按
|
|
358
422
|
`maxContentChars` 封顶、单个协议帧 8 MB、待处理队列 16 帧。撞上限时返回的是明确的错误码
|
|
359
423
|
(`SESSION_LIMIT` / `CRAWL_BUSY` / `BAD_FRAME`),由模型自己退避,而不是把机器吃光。
|