@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/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -29,16 +29,16 @@ Scrapling 及浏览器引擎都是**运行期依赖**——本包通过它们的
|
|
|
29
29
|
- 上游项目:`Scrapling`
|
|
30
30
|
- 上游仓库:https://github.com/D4Vinci/Scrapling
|
|
31
31
|
- 上游许可:BSD 3-Clause,Copyright (c) 2024 Karim Shoair
|
|
32
|
-
- 验证版本:0.
|
|
32
|
+
- 验证版本:0.5
|
|
33
33
|
|
|
34
34
|
本包**使用**而非**包含**以下接口:
|
|
35
35
|
|
|
36
36
|
| 接口 | 用途 |
|
|
37
37
|
| --- | --- |
|
|
38
|
-
| `Fetcher` / `
|
|
38
|
+
| `Fetcher` / `StealthyFetcher` / `FetcherSession` / `StealthySession` / `Selector` / `Spider` / `SessionManager` | 各工具的抓取与抽取实现 |
|
|
39
39
|
| `Convertor._strip_noise_tags`、`Convertor._sanitize_for_ai` | 反注入清洗;`html` 路径的输出不再是字节级原始文档,代价在此 |
|
|
40
40
|
|
|
41
|
-
这些都不是稳定 API 面。README 把 Scrapling 版本上界钉在 `0.
|
|
41
|
+
这些都不是稳定 API 面。README 把 Scrapling 版本上界钉在 `0.6` 之前,正是为了守住这一组接口:
|
|
42
42
|
装到范围外时守卫照常运行,但反注入清洗与爬虫链路可能不按文档描述工作。
|
|
43
43
|
|
|
44
44
|
## 运行期依赖
|
|
@@ -47,12 +47,12 @@ Scrapling 及浏览器引擎都是**运行期依赖**——本包通过它们的
|
|
|
47
47
|
|
|
48
48
|
| 依赖 | 版本 | 许可 | 引入方 |
|
|
49
49
|
| --- | --- | --- | --- |
|
|
50
|
-
| `scrapling` | 0.
|
|
51
|
-
| `playwright` | 1.63.0 | Apache-2.0(Microsoft) |
|
|
52
|
-
| `patchright` | 1.63.0 | Apache-2.0(Microsoft,patch 由 Kaliiiiiiiiii-Vinyzu 提供) |
|
|
50
|
+
| `scrapling` | 0.5 | BSD-3-Clause | Python sidecar |
|
|
51
|
+
| `playwright` | 1.63.0 | Apache-2.0(Microsoft) | 网络守卫 |
|
|
52
|
+
| `patchright` | 1.63.0 | Apache-2.0(Microsoft,patch 由 Kaliiiiiiiiii-Vinyzu 提供) | 浏览器渲染与网络守卫 |
|
|
53
53
|
| `ipaddr.js` | 2.5.0 | MIT | Host 侧 URL 策略的地址分类 |
|
|
54
54
|
|
|
55
55
|
`patchright` 是 Playwright 的补丁分支,与 `playwright` 并存安装:两者是不同的 Python 包,
|
|
56
|
-
|
|
56
|
+
本包按能力探测判断浏览器抓取能不能用。
|
|
57
57
|
|
|
58
58
|
dsh 宿主包(`@deepseek-ai/dsh` 及其子包)是 peer 依赖,由宿主提供、不随本包分发。
|
package/client.js
CHANGED
|
@@ -7,10 +7,10 @@ window.__ModuleLoader__.load({
|
|
|
7
7
|
var exports = module.exports;
|
|
8
8
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
9
9
|
let react = require("react");
|
|
10
|
-
//#region node_modules/.pnpm/@jayyuen66+dsh-plugin-shared@0.1.
|
|
10
|
+
//#region node_modules/.pnpm/@jayyuen66+dsh-plugin-shared@0.1.6_e9e956f77cb41a293465ea365a86fee3/node_modules/@jayyuen66/dsh-plugin-shared/dist/card-apply.js
|
|
11
11
|
function e$1(e, t, n) {
|
|
12
12
|
let r = globalThis;
|
|
13
|
-
if (r[t] === !0) return !1;
|
|
13
|
+
if (Object.hasOwn(r, t) && r[t] === !0) return !1;
|
|
14
14
|
r[t] = !0;
|
|
15
15
|
try {
|
|
16
16
|
e.effect(() => () => {
|
|
@@ -22,7 +22,7 @@ function e$1(e, t, n) {
|
|
|
22
22
|
return !0;
|
|
23
23
|
}
|
|
24
24
|
//#endregion
|
|
25
|
-
//#region node_modules/.pnpm/@jayyuen66+dsh-plugin-shared@0.1.
|
|
25
|
+
//#region node_modules/.pnpm/@jayyuen66+dsh-plugin-shared@0.1.6_e9e956f77cb41a293465ea365a86fee3/node_modules/@jayyuen66/dsh-plugin-shared/dist/record.js
|
|
26
26
|
function e(e) {
|
|
27
27
|
return typeof e == `object` && !!e && !Array.isArray(e);
|
|
28
28
|
}
|
|
@@ -53,8 +53,8 @@ const SETTINGS_GROUPS = [
|
|
|
53
53
|
en: "Python interpreter"
|
|
54
54
|
},
|
|
55
55
|
hint: {
|
|
56
|
-
zh: "
|
|
57
|
-
en: "
|
|
56
|
+
zh: "留空:先用仓内 _env/.venv(装了才用),否则用 PATH 上的 python3;装了 pyenv/conda 时填绝对路径。",
|
|
57
|
+
en: "Empty: use the repo's _env/.venv when it exists, else python3 from PATH; give an absolute path under pyenv/conda."
|
|
58
58
|
},
|
|
59
59
|
fallback: ""
|
|
60
60
|
},
|
|
@@ -150,17 +150,17 @@ const SETTINGS_GROUPS = [
|
|
|
150
150
|
fallback: true
|
|
151
151
|
},
|
|
152
152
|
{
|
|
153
|
-
key: "
|
|
153
|
+
key: "networkEnabled",
|
|
154
154
|
kind: "boolean",
|
|
155
155
|
label: {
|
|
156
|
-
zh: "
|
|
157
|
-
en: "
|
|
156
|
+
zh: "scrapling_session_network",
|
|
157
|
+
en: "scrapling_session_network"
|
|
158
158
|
},
|
|
159
159
|
hint: {
|
|
160
|
-
zh: "
|
|
161
|
-
en: "
|
|
160
|
+
zh: "读已开会话攒下的网络历史;会话需先用 recordNetwork 打开记录。",
|
|
161
|
+
en: "Read a session's recorded network history; the session must have recordNetwork on."
|
|
162
162
|
},
|
|
163
|
-
fallback:
|
|
163
|
+
fallback: true
|
|
164
164
|
},
|
|
165
165
|
{
|
|
166
166
|
key: "sessionEnabled",
|
|
@@ -175,6 +175,19 @@ const SETTINGS_GROUPS = [
|
|
|
175
175
|
},
|
|
176
176
|
fallback: true
|
|
177
177
|
},
|
|
178
|
+
{
|
|
179
|
+
key: "sessionStateEnabled",
|
|
180
|
+
kind: "boolean",
|
|
181
|
+
label: {
|
|
182
|
+
zh: "scrapling_session_state_*",
|
|
183
|
+
en: "scrapling_session_state_*"
|
|
184
|
+
},
|
|
185
|
+
hint: {
|
|
186
|
+
zh: "存/取浏览器登录态;需部署侧配好 sessionStateDir。",
|
|
187
|
+
en: "Save/load browser login state; needs a deployment-side sessionStateDir."
|
|
188
|
+
},
|
|
189
|
+
fallback: true
|
|
190
|
+
},
|
|
178
191
|
{
|
|
179
192
|
key: "crawlEnabled",
|
|
180
193
|
kind: "boolean",
|
|
@@ -183,10 +196,10 @@ const SETTINGS_GROUPS = [
|
|
|
183
196
|
en: "scrapling_crawl"
|
|
184
197
|
},
|
|
185
198
|
hint: {
|
|
186
|
-
zh: "后台 Spider
|
|
187
|
-
en: "Background spider jobs;
|
|
199
|
+
zh: "后台 Spider 作业,只守起始域;需 profile 带作业后端。",
|
|
200
|
+
en: "Background spider jobs confined to the start domain; needs a jobs backend."
|
|
188
201
|
},
|
|
189
|
-
fallback:
|
|
202
|
+
fallback: true
|
|
190
203
|
},
|
|
191
204
|
{
|
|
192
205
|
key: "answerEnabled",
|
|
@@ -332,8 +345,8 @@ const SETTINGS_GROUPS = [
|
|
|
332
345
|
en: "Browser behaviour"
|
|
333
346
|
},
|
|
334
347
|
note: {
|
|
335
|
-
zh: "只在渲染 /
|
|
336
|
-
en: "Only affects the render /
|
|
348
|
+
zh: "只在渲染 / XHR 两条路径上生效。",
|
|
349
|
+
en: "Only affects the render / XHR paths."
|
|
337
350
|
},
|
|
338
351
|
fields: [
|
|
339
352
|
{
|
|
@@ -376,17 +389,17 @@ const SETTINGS_GROUPS = [
|
|
|
376
389
|
fallback: true
|
|
377
390
|
},
|
|
378
391
|
{
|
|
379
|
-
key: "
|
|
380
|
-
kind: "
|
|
392
|
+
key: "pierceShadow",
|
|
393
|
+
kind: "boolean",
|
|
381
394
|
label: {
|
|
382
|
-
zh: "
|
|
383
|
-
en: "
|
|
395
|
+
zh: "穿透 Shadow DOM",
|
|
396
|
+
en: "Pierce Shadow DOM"
|
|
384
397
|
},
|
|
385
398
|
hint: {
|
|
386
|
-
zh: "
|
|
387
|
-
en: "
|
|
399
|
+
zh: "把 open shadow root 里的内容并进正文,默认关;页面把正文封进 shadow DOM 时才打开。",
|
|
400
|
+
en: "Merge open shadow root content into the body; off by default. On when a page hides its content in shadow DOM."
|
|
388
401
|
},
|
|
389
|
-
fallback:
|
|
402
|
+
fallback: false
|
|
390
403
|
},
|
|
391
404
|
{
|
|
392
405
|
key: "waitSelectorState",
|
|
@@ -546,10 +559,10 @@ const SETTINGS_GROUPS = [
|
|
|
546
559
|
en: "Provide the built-in web_fetch"
|
|
547
560
|
},
|
|
548
561
|
hint: {
|
|
549
|
-
zh: "
|
|
550
|
-
en: "
|
|
562
|
+
zh: "默认开;部署配置里仍要写 fetchProvider: \"scrapling\",否则 base bundle 那条 fetchProvider: http 仍然赢。",
|
|
563
|
+
en: "On by default; the deployment config still needs fetchProvider: \"scrapling\", otherwise the base bundle's fetchProvider: http wins."
|
|
551
564
|
},
|
|
552
|
-
fallback:
|
|
565
|
+
fallback: true
|
|
553
566
|
},
|
|
554
567
|
{
|
|
555
568
|
key: "provideWebSearch",
|
|
@@ -559,10 +572,10 @@ const SETTINGS_GROUPS = [
|
|
|
559
572
|
en: "Provide the built-in web_search"
|
|
560
573
|
},
|
|
561
574
|
hint: {
|
|
562
|
-
zh: "
|
|
563
|
-
en: "
|
|
575
|
+
zh: "默认开;还需要配 searchEndpoint(SearXNG 兼容接口)与 searchProvider,否则不会接管。",
|
|
576
|
+
en: "On by default; still needs a SearXNG-compatible searchEndpoint and searchProvider, otherwise it does not take over."
|
|
564
577
|
},
|
|
565
|
-
fallback:
|
|
578
|
+
fallback: true
|
|
566
579
|
}
|
|
567
580
|
]
|
|
568
581
|
},
|
|
@@ -668,6 +681,7 @@ const ROW_CHROME = {
|
|
|
668
681
|
"row.matched": "匹配",
|
|
669
682
|
"row.sessionCount": "会话数",
|
|
670
683
|
"row.session": "会话",
|
|
684
|
+
"row.name": "名称",
|
|
671
685
|
"row.type": "类型",
|
|
672
686
|
"row.start": "起始",
|
|
673
687
|
"row.pageCap": "上限",
|
|
@@ -682,6 +696,7 @@ const ROW_CHROME = {
|
|
|
682
696
|
"row.matched": "Matched",
|
|
683
697
|
"row.sessionCount": "Sessions",
|
|
684
698
|
"row.session": "Session",
|
|
699
|
+
"row.name": "Name",
|
|
685
700
|
"row.type": "Type",
|
|
686
701
|
"row.start": "Start",
|
|
687
702
|
"row.pageCap": "Page cap",
|
|
@@ -1118,6 +1133,10 @@ function SettingsCard(props) {
|
|
|
1118
1133
|
}
|
|
1119
1134
|
//#endregion
|
|
1120
1135
|
//#region src/client-entry.ts
|
|
1136
|
+
/** 一行要展示的一项信息。label 是字典键而不是文案本身:可见文字统一走 locale 服务。 */
|
|
1137
|
+
/** 结果行字段的文案键:多处复用,抽一份免得字面量散落。 */
|
|
1138
|
+
const ROW_TYPE_KEY = "row.type";
|
|
1139
|
+
const ROW_SESSION_KEY = "row.session";
|
|
1121
1140
|
/**
|
|
1122
1141
|
* 需要专用结果行的工具。
|
|
1123
1142
|
*
|
|
@@ -1130,10 +1149,12 @@ const ROW_TOOLS = [
|
|
|
1130
1149
|
"scrapling_extract",
|
|
1131
1150
|
"scrapling_render",
|
|
1132
1151
|
"scrapling_capture_xhr",
|
|
1133
|
-
"scrapling_stealth_fetch",
|
|
1134
1152
|
"scrapling_answer",
|
|
1135
1153
|
"scrapling_session_open",
|
|
1136
1154
|
"scrapling_session_fetch",
|
|
1155
|
+
"scrapling_session_network",
|
|
1156
|
+
"scrapling_session_state_save",
|
|
1157
|
+
"scrapling_session_state_load",
|
|
1137
1158
|
"scrapling_session_list",
|
|
1138
1159
|
"scrapling_session_close",
|
|
1139
1160
|
"scrapling_crawl"
|
|
@@ -1190,10 +1211,10 @@ function buildRow(tool, args, meta) {
|
|
|
1190
1211
|
tool,
|
|
1191
1212
|
title: tool,
|
|
1192
1213
|
fields: [{
|
|
1193
|
-
labelKey:
|
|
1214
|
+
labelKey: ROW_TYPE_KEY,
|
|
1194
1215
|
value: text(parameters["sessionType"])
|
|
1195
1216
|
}, {
|
|
1196
|
-
labelKey:
|
|
1217
|
+
labelKey: ROW_SESSION_KEY,
|
|
1197
1218
|
value: text(projected["sessionId"])
|
|
1198
1219
|
}]
|
|
1199
1220
|
};
|
|
@@ -1201,10 +1222,26 @@ function buildRow(tool, args, meta) {
|
|
|
1201
1222
|
tool,
|
|
1202
1223
|
title: tool,
|
|
1203
1224
|
fields: [{
|
|
1204
|
-
labelKey:
|
|
1225
|
+
labelKey: ROW_SESSION_KEY,
|
|
1205
1226
|
value: text(parameters["sessionId"])
|
|
1206
1227
|
}]
|
|
1207
1228
|
};
|
|
1229
|
+
if (tool === "scrapling_session_network" || tool === "scrapling_session_state_save" || tool === "scrapling_session_state_load") {
|
|
1230
|
+
const fields = [{
|
|
1231
|
+
labelKey: ROW_SESSION_KEY,
|
|
1232
|
+
value: text(parameters["sessionId"])
|
|
1233
|
+
}];
|
|
1234
|
+
const name = text(parameters["name"]);
|
|
1235
|
+
if (name !== "") fields.push({
|
|
1236
|
+
labelKey: "row.name",
|
|
1237
|
+
value: name
|
|
1238
|
+
});
|
|
1239
|
+
return {
|
|
1240
|
+
tool,
|
|
1241
|
+
title: tool,
|
|
1242
|
+
fields
|
|
1243
|
+
};
|
|
1244
|
+
}
|
|
1208
1245
|
if (tool === "scrapling_crawl") return {
|
|
1209
1246
|
tool,
|
|
1210
1247
|
title: tool,
|
|
@@ -1250,6 +1287,7 @@ const ARG_KEYS = [
|
|
|
1250
1287
|
"selector",
|
|
1251
1288
|
"sessionType",
|
|
1252
1289
|
"sessionId",
|
|
1290
|
+
"name",
|
|
1253
1291
|
"maxPages"
|
|
1254
1292
|
];
|
|
1255
1293
|
/**
|
|
@@ -1267,6 +1305,16 @@ function readArgs(args) {
|
|
|
1267
1305
|
}
|
|
1268
1306
|
return values;
|
|
1269
1307
|
}
|
|
1308
|
+
/**
|
|
1309
|
+
* 结果侧投影只在 `phase === "result"` 那一支上有:宿主的 toolview props 把阶段写在**顶层**,
|
|
1310
|
+
* `block` 是按阶段变形的联合(preparing / start / result 各一种节点),meta 只挂在落定的那一支。
|
|
1311
|
+
*
|
|
1312
|
+
* @param props - 宿主给的 owner props
|
|
1313
|
+
* @returns 结果侧投影;没落定时是 undefined
|
|
1314
|
+
*/
|
|
1315
|
+
function resultMetaOf(props) {
|
|
1316
|
+
return props.phase === "result" ? props.block.meta : void 0;
|
|
1317
|
+
}
|
|
1270
1318
|
/** 结果行自己的样式。跟着宿主的语义色走,明暗两套主题都成立。 */
|
|
1271
1319
|
const ROW_CSS = `
|
|
1272
1320
|
.dsh-scrapling-row{display:flex;flex-direction:column;gap:2px;min-width:0}
|
|
@@ -1282,12 +1330,12 @@ const ROW_CSS = `
|
|
|
1282
1330
|
/**
|
|
1283
1331
|
* 一行结果的渲染。
|
|
1284
1332
|
*
|
|
1285
|
-
* 入参走 `block.args
|
|
1286
|
-
*
|
|
1333
|
+
* 入参走 `block.args`,结果侧的投影走顶层 `phase` 选出的 `block.meta`;两者都按「可能还没到」处理 ——
|
|
1334
|
+
* 调用刚发出时既没有 meta 也没有完整入参,这一行就只画标题。
|
|
1287
1335
|
*/
|
|
1288
1336
|
function RowView(props) {
|
|
1289
1337
|
const { toolName, block, inspect, t } = props;
|
|
1290
|
-
const meta =
|
|
1338
|
+
const meta = resultMetaOf(props);
|
|
1291
1339
|
const spec = buildRow(toolName, readArgs(block.args), meta);
|
|
1292
1340
|
const children = [(0, react.createElement)("div", {
|
|
1293
1341
|
className: "dsh-scrapling-rowTitle",
|
|
@@ -1400,6 +1448,7 @@ exports.apply = apply;
|
|
|
1400
1448
|
exports.buildRow = buildRow;
|
|
1401
1449
|
exports.inject = inject;
|
|
1402
1450
|
exports.readArgs = readArgs;
|
|
1451
|
+
exports.resultMetaOf = resultMetaOf;
|
|
1403
1452
|
|
|
1404
1453
|
return module.exports;
|
|
1405
1454
|
},
|
package/cordis.patch.yml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# dsh-scrapling:Scrapling 网页抓取插件(bundle)。
|
|
2
|
-
#
|
|
3
|
-
# scrapling_capture_xhr /
|
|
4
|
-
#
|
|
2
|
+
# 13 个工具(scrapling_fetch / scrapling_extract / scrapling_render /
|
|
3
|
+
# scrapling_capture_xhr / scrapling_session_* / scrapling_crawl / scrapling_answer),
|
|
4
|
+
# 后端是常驻 Python 进程,经 ctx.subprocess 的 stdin/stdout
|
|
5
5
|
# 跑 JSON-lines 协议(stdout 走协议、stderr 走日志)。
|
|
6
6
|
# 每个工具一个 Config .volatile() 开关;关闭时连 systemPrompt 指引段也不注册。
|
|
7
7
|
# 浏览器未就绪时不注册依赖浏览器的工具,并在设置卡给出安装指引。
|