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