@jayyuen66/dsh-scrapling 0.1.16 → 0.2.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/CHANGELOG.md +73 -0
- package/README.md +160 -251
- package/README.zh-CN.md +226 -317
- package/THIRD_PARTY_NOTICES.md +54 -15
- package/bin/dsh-scrapling.mjs +13 -74
- package/client.js +6 -6
- package/cordis.patch.yml +1 -1
- package/docs/DETAIL.md +22 -22
- package/docs/DETAIL.zh.md +27 -27
- package/docs/images/architecture.svg +100 -0
- package/docs/images/architecture.zh.svg +99 -0
- package/docs/images/tool-selection.svg +88 -0
- package/docs/images/tool-selection.zh.svg +88 -0
- package/host.js +26 -45
- package/package.json +67 -62
- package/py/adapters.py +204 -57
- package/py/bridge.py +80 -8
- package/py/cancellation.py +56 -0
- package/py/crawl.py +1 -1
- package/py/document.py +128 -0
- package/py/documents-requirements.txt +1 -0
- package/py/extraction.py +2 -2
- package/py/media.py +4 -3
- package/py/runtime-requirements.txt +4 -3
- package/py/search.py +109 -24
- package/py/session_page.py +92 -24
- package/runtime-manifest.json +6 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1180 560" font-family="-apple-system,'Segoe UI','Noto Sans','PingFang SC','Microsoft YaHei',sans-serif">
|
|
2
|
+
<style>
|
|
3
|
+
.frame { fill: #f6f8fa; stroke: #d0d7de; }
|
|
4
|
+
.inner { fill: #ffffff; stroke: #d0d7de; }
|
|
5
|
+
.arrowline { stroke: #8c959f; stroke-width: 1.6; fill: none; marker-end: url(#head); }
|
|
6
|
+
.pipe { stroke: #658EFF; stroke-width: 2.2; fill: none; marker-end: url(#headAccent); }
|
|
7
|
+
.title { fill: #1f2328; font-size: 20px; font-weight: 600; }
|
|
8
|
+
.head { fill: #1f2328; font-size: 15px; font-weight: 600; }
|
|
9
|
+
.label { fill: #1f2328; font-size: 13px; }
|
|
10
|
+
.small { fill: #57606a; font-size: 12px; }
|
|
11
|
+
.badge { fill: #ffffff; stroke: #658EFF; }
|
|
12
|
+
.badgetext { fill: #33529f; font-size: 12px; font-weight: 600; }
|
|
13
|
+
.accenttext { fill: #33529f; font-size: 13px; font-weight: 600; }
|
|
14
|
+
@media (prefers-color-scheme: dark) {
|
|
15
|
+
.frame { fill: #161b22; stroke: #30363d; }
|
|
16
|
+
.inner { fill: #0d1117; stroke: #30363d; }
|
|
17
|
+
.arrowline { stroke: #8b949e; }
|
|
18
|
+
.title, .head, .label { fill: #e6edf3; }
|
|
19
|
+
.small { fill: #8b949e; }
|
|
20
|
+
.badge { fill: #0d1117; stroke: #658EFF; }
|
|
21
|
+
.badgetext, .accenttext { fill: #7aa2ff; }
|
|
22
|
+
}
|
|
23
|
+
</style>
|
|
24
|
+
<defs>
|
|
25
|
+
<marker id="head" markerWidth="9" markerHeight="9" refX="7" refY="4.5" orient="auto">
|
|
26
|
+
<path d="M0,0 L8,4.5 L0,9 z" fill="#8c959f" class="arrowhead"/>
|
|
27
|
+
</marker>
|
|
28
|
+
<marker id="headAccent" markerWidth="9" markerHeight="9" refX="7" refY="4.5" orient="auto">
|
|
29
|
+
<path d="M0,0 L8,4.5 L0,9 z" fill="#658EFF"/>
|
|
30
|
+
</marker>
|
|
31
|
+
</defs>
|
|
32
|
+
|
|
33
|
+
<text x="590" y="34" text-anchor="middle" class="title">dsh-scrapling —— 单个常驻 Python 进程</text>
|
|
34
|
+
|
|
35
|
+
<!-- dsh host -->
|
|
36
|
+
<rect x="24" y="70" width="286" height="380" rx="10" class="frame"/>
|
|
37
|
+
<text x="44" y="100" class="head">dsh 宿主</text>
|
|
38
|
+
<text x="44" y="130" class="label">模型</text>
|
|
39
|
+
<text x="44" y="158" class="label">ctx.tools —— 20 个 scrapling_* 工具</text>
|
|
40
|
+
<text x="44" y="186" class="label">ctx.web —— web_fetch / web_search</text>
|
|
41
|
+
<text x="44" y="214" class="label">设置卡(shared 客户端供应行)</text>
|
|
42
|
+
<text x="44" y="242" class="label">ctx.jobs —— 爬虫后台作业</text>
|
|
43
|
+
<text x="44" y="270" class="small">每条工具定义带 guidance 摘要;</text>
|
|
44
|
+
<text x="44" y="288" class="small">全文注册成 skill `scrapling`</text>
|
|
45
|
+
<text x="44" y="322" class="small">条件注册:环境撑不起的工具</text>
|
|
46
|
+
<text x="44" y="340" class="small">根本不会出现在模型面前</text>
|
|
47
|
+
|
|
48
|
+
<!-- plugin bridge -->
|
|
49
|
+
<rect x="366" y="170" width="240" height="180" rx="10" class="frame"/>
|
|
50
|
+
<text x="386" y="200" class="head">插件 host.js</text>
|
|
51
|
+
<rect x="386" y="216" width="200" height="40" rx="8" class="inner"/>
|
|
52
|
+
<text x="486" y="240" text-anchor="middle" class="accenttext">SidecarClient</text>
|
|
53
|
+
<text x="386" y="286" class="label">stdin/stdout 上的 JSON-lines 协议</text>
|
|
54
|
+
<text x="386" y="308" class="small">stdout 只走协议帧,stderr 走日志</text>
|
|
55
|
+
<text x="386" y="326" class="small">插件卸载时进程保证被回收</text>
|
|
56
|
+
|
|
57
|
+
<!-- python sidecar -->
|
|
58
|
+
<rect x="662" y="70" width="266" height="380" rx="10" class="frame"/>
|
|
59
|
+
<text x="682" y="100" class="head">Python sidecar —— bridge.py</text>
|
|
60
|
+
<rect x="682" y="116" width="226" height="46" rx="8" class="inner"/>
|
|
61
|
+
<text x="795" y="136" text-anchor="middle" class="label">Scrapling Fetcher</text>
|
|
62
|
+
<text x="795" y="152" text-anchor="middle" class="small">curl_cffi · 静态 · 无 JS</text>
|
|
63
|
+
<rect x="682" y="170" width="226" height="46" rx="8" class="inner"/>
|
|
64
|
+
<text x="795" y="190" text-anchor="middle" class="label">StealthySession</text>
|
|
65
|
+
<text x="795" y="206" text-anchor="middle" class="small">patchright → Chromium</text>
|
|
66
|
+
<rect x="682" y="224" width="226" height="46" rx="8" class="inner"/>
|
|
67
|
+
<text x="795" y="244" text-anchor="middle" class="label">Selector + adaptive</text>
|
|
68
|
+
<text x="795" y="260" text-anchor="middle" class="small">选择器自愈 · SQLite 指纹库</text>
|
|
69
|
+
<rect x="682" y="278" width="226" height="46" rx="8" class="inner"/>
|
|
70
|
+
<text x="795" y="298" text-anchor="middle" class="label">Spider 爬虫</text>
|
|
71
|
+
<text x="795" y="314" text-anchor="middle" class="small">content / sitemap / feed / shopify</text>
|
|
72
|
+
<rect x="682" y="332" width="226" height="46" rx="8" class="inner"/>
|
|
73
|
+
<text x="795" y="352" text-anchor="middle" class="label">pypdf</text>
|
|
74
|
+
<text x="795" y="368" text-anchor="middle" class="small">流式 PDF 文本</text>
|
|
75
|
+
<text x="682" y="410" class="small">cookie、页面池与指纹库跨请求</text>
|
|
76
|
+
<text x="682" y="428" class="small">保活,全靠这一个进程</text>
|
|
77
|
+
|
|
78
|
+
<!-- target sites -->
|
|
79
|
+
<rect x="986" y="170" width="170" height="180" rx="10" class="frame"/>
|
|
80
|
+
<text x="1071" y="248" text-anchor="middle" class="head">目标站点</text>
|
|
81
|
+
<text x="1071" y="274" text-anchor="middle" class="small">仅 http(s)</text>
|
|
82
|
+
|
|
83
|
+
<!-- pipes -->
|
|
84
|
+
<path d="M310 260 H 366" class="pipe"/>
|
|
85
|
+
<path d="M606 260 H 662" class="pipe"/>
|
|
86
|
+
<path d="M928 260 H 986" class="pipe"/>
|
|
87
|
+
|
|
88
|
+
<!-- SSRF gate badge on the outbound arrow -->
|
|
89
|
+
<rect x="922" y="196" width="152" height="42" rx="8" class="badge"/>
|
|
90
|
+
<text x="998" y="213" text-anchor="middle" class="badgetext">SSRF 闸门</text>
|
|
91
|
+
<text x="998" y="229" text-anchor="middle" class="small">协议 · 凭据 · DNS 全量解析</text>
|
|
92
|
+
|
|
93
|
+
<!-- data dir strip -->
|
|
94
|
+
<rect x="366" y="470" width="562" height="56" rx="10" class="frame"/>
|
|
95
|
+
<text x="386" y="494" class="label">dataDir(默认 ~/.dsh-scrapling)</text>
|
|
96
|
+
<text x="386" y="514" class="small">runtime/venv(托管依赖)· downloads/ · elements_storage.db(adaptive 指纹库)</text>
|
|
97
|
+
<path d="M486 350 V 470" class="arrowline"/>
|
|
98
|
+
<path d="M795 450 V 470" class="arrowline"/>
|
|
99
|
+
</svg>
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1180 500" font-family="-apple-system,'Segoe UI','Noto Sans','PingFang SC','Microsoft YaHei',sans-serif">
|
|
2
|
+
<style>
|
|
3
|
+
.frame { fill: #f6f8fa; stroke: #d0d7de; }
|
|
4
|
+
.inner { fill: #ffffff; stroke: #d0d7de; }
|
|
5
|
+
.pill { fill: #658EFF; }
|
|
6
|
+
.pilltext { fill: #ffffff; font-size: 14px; font-weight: 600; }
|
|
7
|
+
.arrowline { stroke: #8c959f; stroke-width: 1.6; fill: none; marker-end: url(#head); }
|
|
8
|
+
.title { fill: #1f2328; font-size: 20px; font-weight: 600; }
|
|
9
|
+
.head { fill: #1f2328; font-size: 15px; font-weight: 600; }
|
|
10
|
+
.label { fill: #1f2328; font-size: 13px; font-weight: 600; }
|
|
11
|
+
.small { fill: #57606a; font-size: 12px; }
|
|
12
|
+
.toolname { fill: #33529f; font-size: 12.5px; font-weight: 600; }
|
|
13
|
+
.situation { fill: #1f2328; font-size: 13px; font-weight: 600; }
|
|
14
|
+
@media (prefers-color-scheme: dark) {
|
|
15
|
+
.frame { fill: #161b22; stroke: #30363d; }
|
|
16
|
+
.inner { fill: #0d1117; stroke: #30363d; }
|
|
17
|
+
.arrowline { stroke: #8b949e; }
|
|
18
|
+
.title, .head, .situation { fill: #e6edf3; }
|
|
19
|
+
.small { fill: #8b949e; }
|
|
20
|
+
.toolname { fill: #7aa2ff; }
|
|
21
|
+
}
|
|
22
|
+
</style>
|
|
23
|
+
<defs>
|
|
24
|
+
<marker id="head" markerWidth="9" markerHeight="9" refX="7" refY="4.5" orient="auto">
|
|
25
|
+
<path d="M0,0 L8,4.5 L0,9 z" fill="#8c959f"/>
|
|
26
|
+
</marker>
|
|
27
|
+
</defs>
|
|
28
|
+
|
|
29
|
+
<text x="590" y="34" text-anchor="middle" class="title">Which tool reads this page?</text>
|
|
30
|
+
|
|
31
|
+
<!-- main path -->
|
|
32
|
+
<rect x="24" y="106" width="176" height="48" rx="24" class="pill"/>
|
|
33
|
+
<text x="112" y="135" text-anchor="middle" class="pilltext">Need web content</text>
|
|
34
|
+
|
|
35
|
+
<path d="M200 130 H 248" class="arrowline"/>
|
|
36
|
+
<rect x="248" y="98" width="252" height="64" rx="10" class="inner"/>
|
|
37
|
+
<text x="374" y="124" text-anchor="middle" class="head">scrapling_fetch</text>
|
|
38
|
+
<text x="374" y="146" text-anchor="middle" class="small">static first — curl_cffi, cheap and fast</text>
|
|
39
|
+
|
|
40
|
+
<path d="M500 130 H 548" class="arrowline"/>
|
|
41
|
+
<rect x="548" y="98" width="272" height="64" rx="10" class="frame"/>
|
|
42
|
+
<text x="684" y="124" text-anchor="middle" class="head">body under 200 characters</text>
|
|
43
|
+
<text x="684" y="146" text-anchor="middle" class="small">and a browser engine is installed?</text>
|
|
44
|
+
|
|
45
|
+
<path d="M684 98 V 70 H 866 V 88" class="arrowline"/>
|
|
46
|
+
<text x="700" y="80" class="small">yes</text>
|
|
47
|
+
<rect x="866" y="40" width="290" height="60" rx="10" class="inner"/>
|
|
48
|
+
<text x="1011" y="64" text-anchor="middle" class="head">scrapling_render</text>
|
|
49
|
+
<text x="1011" y="86" text-anchor="middle" class="small">full browser pass — slower, heavier</text>
|
|
50
|
+
|
|
51
|
+
<path d="M684 162 V 190 H 866" class="arrowline"/>
|
|
52
|
+
<text x="700" y="182" class="small">no</text>
|
|
53
|
+
<rect x="866" y="164" width="290" height="52" rx="10" class="inner"/>
|
|
54
|
+
<text x="1011" y="195" text-anchor="middle" class="label">use the fetched body</text>
|
|
55
|
+
|
|
56
|
+
<!-- special cases -->
|
|
57
|
+
<text x="24" y="258" class="head">Pick by situation</text>
|
|
58
|
+
|
|
59
|
+
<rect x="24" y="274" width="368" height="92" rx="10" class="frame"/>
|
|
60
|
+
<text x="44" y="300" class="situation">HTML already in hand</text>
|
|
61
|
+
<text x="44" y="322" class="toolname">scrapling_extract · scrapling_locate · scrapling_links</text>
|
|
62
|
+
<text x="44" y="344" class="small">offline parsers — they never send a request</text>
|
|
63
|
+
|
|
64
|
+
<rect x="414" y="274" width="368" height="92" rx="10" class="frame"/>
|
|
65
|
+
<text x="434" y="300" class="situation">Data lives behind a JSON API</text>
|
|
66
|
+
<text x="434" y="322" class="toolname">scrapling_capture_xhr</text>
|
|
67
|
+
<text x="434" y="344" class="small">find the endpoint, then fetch the endpoint itself</text>
|
|
68
|
+
|
|
69
|
+
<rect x="804" y="274" width="368" height="92" rx="10" class="frame"/>
|
|
70
|
+
<text x="824" y="300" class="situation">Login state, or many pages on one site</text>
|
|
71
|
+
<text x="824" y="322" class="toolname">scrapling_session_open → session_fetch / read / act</text>
|
|
72
|
+
<text x="824" y="344" class="small">cookies and the browser stay alive across calls</text>
|
|
73
|
+
|
|
74
|
+
<rect x="24" y="388" width="368" height="92" rx="10" class="frame"/>
|
|
75
|
+
<text x="44" y="414" class="situation">The whole site</text>
|
|
76
|
+
<text x="44" y="436" class="toolname">scrapling_crawl</text>
|
|
77
|
+
<text x="44" y="458" class="small">background job — watch with job_list / job_output</text>
|
|
78
|
+
|
|
79
|
+
<rect x="414" y="388" width="368" height="92" rx="10" class="frame"/>
|
|
80
|
+
<text x="434" y="414" class="situation">A PDF document</text>
|
|
81
|
+
<text x="434" y="436" class="toolname">scrapling_read_document</text>
|
|
82
|
+
<text x="434" y="458" class="small">streamed text and page count (optional pypdf pack)</text>
|
|
83
|
+
|
|
84
|
+
<rect x="804" y="388" width="368" height="92" rx="10" class="frame"/>
|
|
85
|
+
<text x="824" y="414" class="situation">A question about one page</text>
|
|
86
|
+
<text x="824" y="436" class="toolname">scrapling_answer</text>
|
|
87
|
+
<text x="824" y="458" class="small">fetches the page, then asks the model — untrusted input framed as data</text>
|
|
88
|
+
</svg>
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1180 500" font-family="-apple-system,'Segoe UI','Noto Sans','PingFang SC','Microsoft YaHei',sans-serif">
|
|
2
|
+
<style>
|
|
3
|
+
.frame { fill: #f6f8fa; stroke: #d0d7de; }
|
|
4
|
+
.inner { fill: #ffffff; stroke: #d0d7de; }
|
|
5
|
+
.pill { fill: #658EFF; }
|
|
6
|
+
.pilltext { fill: #ffffff; font-size: 14px; font-weight: 600; }
|
|
7
|
+
.arrowline { stroke: #8c959f; stroke-width: 1.6; fill: none; marker-end: url(#head); }
|
|
8
|
+
.title { fill: #1f2328; font-size: 20px; font-weight: 600; }
|
|
9
|
+
.head { fill: #1f2328; font-size: 15px; font-weight: 600; }
|
|
10
|
+
.label { fill: #1f2328; font-size: 13px; font-weight: 600; }
|
|
11
|
+
.small { fill: #57606a; font-size: 12px; }
|
|
12
|
+
.toolname { fill: #33529f; font-size: 12.5px; font-weight: 600; }
|
|
13
|
+
.situation { fill: #1f2328; font-size: 13px; font-weight: 600; }
|
|
14
|
+
@media (prefers-color-scheme: dark) {
|
|
15
|
+
.frame { fill: #161b22; stroke: #30363d; }
|
|
16
|
+
.inner { fill: #0d1117; stroke: #30363d; }
|
|
17
|
+
.arrowline { stroke: #8b949e; }
|
|
18
|
+
.title, .head, .situation { fill: #e6edf3; }
|
|
19
|
+
.small { fill: #8b949e; }
|
|
20
|
+
.toolname { fill: #7aa2ff; }
|
|
21
|
+
}
|
|
22
|
+
</style>
|
|
23
|
+
<defs>
|
|
24
|
+
<marker id="head" markerWidth="9" markerHeight="9" refX="7" refY="4.5" orient="auto">
|
|
25
|
+
<path d="M0,0 L8,4.5 L0,9 z" fill="#8c959f"/>
|
|
26
|
+
</marker>
|
|
27
|
+
</defs>
|
|
28
|
+
|
|
29
|
+
<text x="590" y="34" text-anchor="middle" class="title">这一次该用哪个工具?</text>
|
|
30
|
+
|
|
31
|
+
<!-- main path -->
|
|
32
|
+
<rect x="24" y="106" width="176" height="48" rx="24" class="pill"/>
|
|
33
|
+
<text x="112" y="135" text-anchor="middle" class="pilltext">需要网页内容</text>
|
|
34
|
+
|
|
35
|
+
<path d="M200 130 H 248" class="arrowline"/>
|
|
36
|
+
<rect x="248" y="98" width="252" height="64" rx="10" class="inner"/>
|
|
37
|
+
<text x="374" y="124" text-anchor="middle" class="head">scrapling_fetch</text>
|
|
38
|
+
<text x="374" y="146" text-anchor="middle" class="small">先静态抓取 —— curl_cffi,又快又省</text>
|
|
39
|
+
|
|
40
|
+
<path d="M500 130 H 548" class="arrowline"/>
|
|
41
|
+
<rect x="548" y="98" width="272" height="64" rx="10" class="frame"/>
|
|
42
|
+
<text x="684" y="124" text-anchor="middle" class="head">正文少于 200 字符</text>
|
|
43
|
+
<text x="684" y="146" text-anchor="middle" class="small">且这台机器装了浏览器?</text>
|
|
44
|
+
|
|
45
|
+
<path d="M684 98 V 70 H 866 V 88" class="arrowline"/>
|
|
46
|
+
<text x="700" y="80" class="small">是</text>
|
|
47
|
+
<rect x="866" y="40" width="290" height="60" rx="10" class="inner"/>
|
|
48
|
+
<text x="1011" y="64" text-anchor="middle" class="head">scrapling_render</text>
|
|
49
|
+
<text x="1011" y="86" text-anchor="middle" class="small">完整浏览器渲染 —— 更慢更重</text>
|
|
50
|
+
|
|
51
|
+
<path d="M684 162 V 190 H 866" class="arrowline"/>
|
|
52
|
+
<text x="700" y="182" class="small">否</text>
|
|
53
|
+
<rect x="866" y="164" width="290" height="52" rx="10" class="inner"/>
|
|
54
|
+
<text x="1011" y="195" text-anchor="middle" class="label">直接用抓到的正文</text>
|
|
55
|
+
|
|
56
|
+
<!-- special cases -->
|
|
57
|
+
<text x="24" y="258" class="head">按情形选工具</text>
|
|
58
|
+
|
|
59
|
+
<rect x="24" y="274" width="368" height="92" rx="10" class="frame"/>
|
|
60
|
+
<text x="44" y="300" class="situation">HTML 已在手</text>
|
|
61
|
+
<text x="44" y="322" class="toolname">scrapling_extract · scrapling_locate · scrapling_links</text>
|
|
62
|
+
<text x="44" y="344" class="small">离线解析器 —— 一次请求都不发</text>
|
|
63
|
+
|
|
64
|
+
<rect x="414" y="274" width="368" height="92" rx="10" class="frame"/>
|
|
65
|
+
<text x="434" y="300" class="situation">数据在 JSON 接口里</text>
|
|
66
|
+
<text x="434" y="322" class="toolname">scrapling_capture_xhr</text>
|
|
67
|
+
<text x="434" y="344" class="small">先找到接口,再对接口地址单独抓一次</text>
|
|
68
|
+
|
|
69
|
+
<rect x="804" y="274" width="368" height="92" rx="10" class="frame"/>
|
|
70
|
+
<text x="824" y="300" class="situation">要登录态,或同一站点的多个页面</text>
|
|
71
|
+
<text x="824" y="322" class="toolname">scrapling_session_open → session_fetch / read / act</text>
|
|
72
|
+
<text x="824" y="344" class="small">cookie 与浏览器实例跨调用保活</text>
|
|
73
|
+
|
|
74
|
+
<rect x="24" y="388" width="368" height="92" rx="10" class="frame"/>
|
|
75
|
+
<text x="44" y="414" class="situation">整站抓取</text>
|
|
76
|
+
<text x="44" y="436" class="toolname">scrapling_crawl</text>
|
|
77
|
+
<text x="44" y="458" class="small">后台作业 —— 用 job_list / job_output 看进度</text>
|
|
78
|
+
|
|
79
|
+
<rect x="414" y="388" width="368" height="92" rx="10" class="frame"/>
|
|
80
|
+
<text x="434" y="414" class="situation">一份 PDF</text>
|
|
81
|
+
<text x="434" y="436" class="toolname">scrapling_read_document</text>
|
|
82
|
+
<text x="434" y="458" class="small">流式文本与页数(可选 pypdf 能力包)</text>
|
|
83
|
+
|
|
84
|
+
<rect x="804" y="388" width="368" height="92" rx="10" class="frame"/>
|
|
85
|
+
<text x="824" y="414" class="situation">就一个页面提个问题</text>
|
|
86
|
+
<text x="824" y="436" class="toolname">scrapling_answer</text>
|
|
87
|
+
<text x="824" y="458" class="small">先抓正文再交给模型;正文按不可信数据处理</text>
|
|
88
|
+
</svg>
|