@jayyuen66/dsh-scrapling 0.1.6 → 0.1.8
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 +57 -1
- package/README.md +13 -11
- package/README.zh-CN.md +13 -11
- package/bin/dsh-scrapling.mjs +68 -69
- package/client.js +3 -106
- package/cordis.patch.yml +10 -3
- package/docs/DETAIL.md +8 -8
- package/docs/DETAIL.zh.md +8 -8
- package/host.js +20 -20
- package/package.json +56 -53
- package/py/adapters.py +9 -5
- package/py/bridge.py +51 -14
- package/py/extraction.py +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jayyuen66/dsh-scrapling",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Scrapling 网页抓取插件(dsh):静态/浏览器抓取 + CSS/XPath 结构化抽取 + 选择器自愈 + capture_xhr 与会话网络历史 + 登录态存取 + Spider 爬虫,由常驻 Python 进程驱动。",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|
|
@@ -75,65 +75,64 @@
|
|
|
75
75
|
"zod": "4.6.7"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
|
-
"@deepseek-ai/cordis": "4.0
|
|
79
|
-
"@deepseek-ai/cordis-plugin-include": "1.0
|
|
80
|
-
"@deepseek-ai/cordis-plugin-loader": "1.0
|
|
81
|
-
"@deepseek-ai/dsh-api-remotes": "0.2.2-
|
|
82
|
-
"@deepseek-ai/dsh-client-locale": "0.2.2-
|
|
83
|
-
"@deepseek-ai/dsh-client-store": "0.2.2-
|
|
84
|
-
"@deepseek-ai/dsh-client-ui-chat": "0.2.2-
|
|
85
|
-
"@deepseek-ai/dsh-client-ui-conversation": "0.2.2-
|
|
86
|
-
"@deepseek-ai/dsh-client-ui-layout": "0.2.2-
|
|
87
|
-
"@deepseek-ai/dsh-client-ui-plugin-manager": "0.2.2-
|
|
88
|
-
"@deepseek-ai/dsh-client-ui-renderer": "0.2.2-
|
|
89
|
-
"@deepseek-ai/dsh-client-ui-settings": "0.2.2-
|
|
90
|
-
"@deepseek-ai/dsh-client-ui-slots": "0.2.2-
|
|
91
|
-
"@deepseek-ai/dsh-client-ui-tool": "0.2.2-
|
|
92
|
-
"@deepseek-ai/dsh-host-webserver": "0.2.2-
|
|
93
|
-
"@deepseek-ai/dsh-http-proxy": "0.2.2-
|
|
94
|
-
"@deepseek-ai/dsh-jobs": "0.2.2-
|
|
95
|
-
"@deepseek-ai/dsh-jobs-local": "0.2.2-
|
|
96
|
-
"@deepseek-ai/dsh-output-retention": "0.2.2-
|
|
97
|
-
"@deepseek-ai/dsh-package-manifest": "0.2.2-
|
|
98
|
-
"@deepseek-ai/dsh-
|
|
99
|
-
"@deepseek-ai/dsh-
|
|
100
|
-
"@deepseek-ai/dsh-
|
|
101
|
-
"@deepseek-ai/dsh-
|
|
102
|
-
"@deepseek-ai/dsh-
|
|
103
|
-
"@deepseek-ai/dsh-
|
|
104
|
-
"@deepseek-ai/dsh-
|
|
105
|
-
"@deepseek-ai/dsh-
|
|
106
|
-
"@deepseek-ai/dsh-
|
|
107
|
-
"@deepseek-ai/dsh-
|
|
108
|
-
"@deepseek-ai/dsh-
|
|
109
|
-
"@deepseek-ai/dsh-
|
|
110
|
-
"@deepseek-ai/
|
|
111
|
-
"@deepseek-ai/schemastery": "3.18.6-alpha.1",
|
|
78
|
+
"@deepseek-ai/cordis": "4.1.0",
|
|
79
|
+
"@deepseek-ai/cordis-plugin-include": "1.1.0",
|
|
80
|
+
"@deepseek-ai/cordis-plugin-loader": "1.1.0",
|
|
81
|
+
"@deepseek-ai/dsh-api-remotes": "0.2.2-rc.1",
|
|
82
|
+
"@deepseek-ai/dsh-client-locale": "0.2.2-rc.1",
|
|
83
|
+
"@deepseek-ai/dsh-client-store": "0.2.2-rc.1",
|
|
84
|
+
"@deepseek-ai/dsh-client-ui-chat": "0.2.2-rc.1",
|
|
85
|
+
"@deepseek-ai/dsh-client-ui-conversation": "0.2.2-rc.1",
|
|
86
|
+
"@deepseek-ai/dsh-client-ui-layout": "0.2.2-rc.1",
|
|
87
|
+
"@deepseek-ai/dsh-client-ui-plugin-manager": "0.2.2-rc.1",
|
|
88
|
+
"@deepseek-ai/dsh-client-ui-renderer": "0.2.2-rc.1",
|
|
89
|
+
"@deepseek-ai/dsh-client-ui-settings": "0.2.2-rc.1",
|
|
90
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.2.2-rc.1",
|
|
91
|
+
"@deepseek-ai/dsh-client-ui-tool": "0.2.2-rc.1",
|
|
92
|
+
"@deepseek-ai/dsh-host-webserver": "0.2.2-rc.1",
|
|
93
|
+
"@deepseek-ai/dsh-http-proxy": "0.2.2-rc.1",
|
|
94
|
+
"@deepseek-ai/dsh-jobs": "0.2.2-rc.1",
|
|
95
|
+
"@deepseek-ai/dsh-jobs-local": "0.2.2-rc.1",
|
|
96
|
+
"@deepseek-ai/dsh-output-retention": "0.2.2-rc.1",
|
|
97
|
+
"@deepseek-ai/dsh-package-manifest": "0.2.2-rc.1",
|
|
98
|
+
"@deepseek-ai/dsh-sandbox": "0.2.2-rc.1",
|
|
99
|
+
"@deepseek-ai/dsh-scope": "0.2.2-rc.1",
|
|
100
|
+
"@deepseek-ai/dsh-session": "0.2.2-rc.1",
|
|
101
|
+
"@deepseek-ai/dsh-settings": "0.2.2-rc.1",
|
|
102
|
+
"@deepseek-ai/dsh-shell": "0.2.2-rc.1",
|
|
103
|
+
"@deepseek-ai/dsh-subprocess": "0.2.2-rc.1",
|
|
104
|
+
"@deepseek-ai/dsh-system-prompt": "0.2.2-rc.1",
|
|
105
|
+
"@deepseek-ai/dsh-tool-executor-native": "0.2.2-rc.1",
|
|
106
|
+
"@deepseek-ai/dsh-tools": "0.2.2-rc.1",
|
|
107
|
+
"@deepseek-ai/dsh-typert-protocol": "0.2.2-rc.1",
|
|
108
|
+
"@deepseek-ai/dsh-user-approval": "0.2.2-rc.1",
|
|
109
|
+
"@deepseek-ai/dsh-web": "0.2.2-rc.1",
|
|
110
|
+
"@deepseek-ai/schemastery": "3.19.0",
|
|
112
111
|
"@e18e/eslint-plugin": "0.8.1",
|
|
113
|
-
"@jayyuen66/dsh-plugin-shared": "0.2.
|
|
112
|
+
"@jayyuen66/dsh-plugin-shared": "^0.2.4",
|
|
114
113
|
"@types/node": "26.6.6",
|
|
115
114
|
"@types/react": "19.3.0",
|
|
116
|
-
"@vitest/coverage-v8": "5.0
|
|
117
|
-
"eslint-plugin-regexp": "3.3.
|
|
115
|
+
"@vitest/coverage-v8": "5.1.0",
|
|
116
|
+
"eslint-plugin-regexp": "3.3.3",
|
|
118
117
|
"eslint-plugin-sonarjs": "4.2.2",
|
|
119
118
|
"eslint-plugin-zod": "5.2.2",
|
|
120
119
|
"fast-check": "4.10.2",
|
|
121
|
-
"oxfmt": "0.
|
|
122
|
-
"oxlint": "1.
|
|
120
|
+
"oxfmt": "0.76.0",
|
|
121
|
+
"oxlint": "1.91.0",
|
|
123
122
|
"oxlint-tsgolint": "7.0.2005",
|
|
124
123
|
"react": "^19.3.0",
|
|
125
|
-
"rolldown": "1.2.
|
|
124
|
+
"rolldown": "1.2.16",
|
|
126
125
|
"typescript": "7.0.2",
|
|
127
|
-
"vite": "8.3.
|
|
128
|
-
"vitest": "5.0
|
|
126
|
+
"vite": "8.3.6",
|
|
127
|
+
"vitest": "5.1.0"
|
|
129
128
|
},
|
|
130
129
|
"peerDependencies": {
|
|
131
|
-
"@deepseek-ai/dsh": "^0.2.1-rc.3",
|
|
132
|
-
"@deepseek-ai/dsh-output-retention": "^0.2.1-rc.3",
|
|
133
|
-
"@deepseek-ai/dsh-tools": "^0.2.1-rc.3",
|
|
134
|
-
"@deepseek-ai/dsh-typert-protocol": "^0.2.1-rc.3",
|
|
135
|
-
"@deepseek-ai/dsh-web": "^0.2.1-rc.3",
|
|
136
|
-
"@deepseek-ai/schemastery": "^3.18.6-alpha.1"
|
|
130
|
+
"@deepseek-ai/dsh": "^0.2.1-rc.5 || ^0.2.2-alpha.3",
|
|
131
|
+
"@deepseek-ai/dsh-output-retention": "^0.2.1-rc.5 || ^0.2.2-alpha.3",
|
|
132
|
+
"@deepseek-ai/dsh-tools": "^0.2.1-rc.5 || ^0.2.2-alpha.3",
|
|
133
|
+
"@deepseek-ai/dsh-typert-protocol": "^0.2.1-rc.5 || ^0.2.2-alpha.3",
|
|
134
|
+
"@deepseek-ai/dsh-web": "^0.2.1-rc.5 || ^0.2.2-alpha.3",
|
|
135
|
+
"@deepseek-ai/schemastery": "^3.18.5 || ^3.18.6-alpha.1"
|
|
137
136
|
},
|
|
138
137
|
"peerDependenciesMeta": {
|
|
139
138
|
"@deepseek-ai/dsh": {
|
|
@@ -145,8 +144,8 @@
|
|
|
145
144
|
},
|
|
146
145
|
"icon": "icon.svg",
|
|
147
146
|
"engines": {
|
|
148
|
-
"dsh": "^0.2.1-rc.3",
|
|
149
|
-
"node": ">=
|
|
147
|
+
"dsh": "^0.2.1-rc.5 || ^0.2.2-alpha.3",
|
|
148
|
+
"node": ">=24.9.0"
|
|
150
149
|
},
|
|
151
150
|
"dsh": {
|
|
152
151
|
"manifestVersion": 1,
|
|
@@ -155,7 +154,10 @@
|
|
|
155
154
|
},
|
|
156
155
|
"client": {
|
|
157
156
|
"platform": "web",
|
|
158
|
-
"immediately": true
|
|
157
|
+
"immediately": true,
|
|
158
|
+
"external": [
|
|
159
|
+
"@jayyuen66/dsh-plugin-shared/client"
|
|
160
|
+
]
|
|
159
161
|
}
|
|
160
162
|
},
|
|
161
163
|
"scripts": {
|
|
@@ -165,11 +167,12 @@
|
|
|
165
167
|
"lint": "oxlint .",
|
|
166
168
|
"test": "vitest run --coverage",
|
|
167
169
|
"test:watch": "vitest",
|
|
168
|
-
"check": "npm run --loglevel=warn typecheck && npm run --loglevel=warn lint && npm run --loglevel=warn build:client && npm run --loglevel=warn build && npm run --loglevel=warn test && npm run --loglevel=warn fmt:check && npm run --loglevel=warn check:py",
|
|
170
|
+
"check": "npm run --loglevel=warn typecheck && npm run --loglevel=warn lint && npm run --loglevel=warn build:client && npm run --loglevel=warn build && npm run --loglevel=warn test && npm run --loglevel=warn gate:eol && npm run --loglevel=warn fmt:check && npm run --loglevel=warn check:py",
|
|
169
171
|
"fmt:check": "oxfmt --check .",
|
|
170
172
|
"py": "node py-launcher.mjs",
|
|
171
173
|
"py:which": "node py-launcher.mjs --which",
|
|
172
174
|
"face:py": "node face-py.mjs",
|
|
175
|
+
"gate:eol": "node eol-gate.mjs",
|
|
173
176
|
"lint:py": "npm run --loglevel=warn py -- -m ruff check py/",
|
|
174
177
|
"fmt:py": "npm run --loglevel=warn py -- -m ruff format --check py/",
|
|
175
178
|
"typecheck:py": "npm run --loglevel=warn py -- -m mypy py/",
|
package/py/adapters.py
CHANGED
|
@@ -759,7 +759,6 @@ SESSION_ONLY_KEYS = frozenset(
|
|
|
759
759
|
"block_ads",
|
|
760
760
|
"block_webrtc",
|
|
761
761
|
"blocked_domains",
|
|
762
|
-
"cdp_url",
|
|
763
762
|
"cookies",
|
|
764
763
|
"disable_resources",
|
|
765
764
|
"dns_over_https",
|
|
@@ -787,9 +786,14 @@ SESSION_ONLY_KEYS = frozenset(
|
|
|
787
786
|
# 部署命名空间里的浏览器旋钮:源键 → 引擎参数名 → 期望类型。类型逐项写死,是因为这一层
|
|
788
787
|
# 与模型入参走同一条通道而它承载的是**部署表态**:类型错了静默生效比报错更糟(例如
|
|
789
788
|
# maxRecordedRequests 收到字符串,上游会拿它当容量直接炸会话构造)。
|
|
789
|
+
#
|
|
790
|
+
# 这里没有 CDP 端点那一枚:Scrapling 0.5.1 把 `cdp_url` 收归 RemoteSession,递给
|
|
791
|
+
# StealthSession 会 `TypeError`(`engines/_browsers/_validators.py` 的
|
|
792
|
+
# 「cdp_url and new_context require RemoteSession」那条),而本包没有远端会话模式。
|
|
793
|
+
# 递过去在 0.5 上能用、在 0.5.1 上炸会话构造,等于让同一条文档范围 `>=0.5,<0.6` 里
|
|
794
|
+
# 的两个版本行为分叉,所以这个旋钮整体撤掉。
|
|
790
795
|
_DEPLOYMENT_KNOBS: tuple[tuple[str, str, type], ...] = (
|
|
791
796
|
("browserExecutablePath", "executable_path", str),
|
|
792
|
-
("browserCdpUrl", "cdp_url", str),
|
|
793
797
|
("browserInitScript", "init_script", str),
|
|
794
798
|
("browserRealChrome", "real_chrome", bool),
|
|
795
799
|
("browserDnsOverHttps", "dns_over_https", bool),
|
|
@@ -921,7 +925,7 @@ def _session_browser_params(args: dict[str, Any]) -> dict[str, Any]:
|
|
|
921
925
|
"""会话构造期的浏览器参数:只收**只有开场才生效**的那些键。
|
|
922
926
|
|
|
923
927
|
会话内每次 fetch 传 ``block_ads`` / ``record_requests`` / ``executable_path`` /
|
|
924
|
-
``
|
|
928
|
+
``locale`` / ``timezone_id`` / ``useragent`` / ``headless`` 都会被
|
|
925
929
|
``validate_fetch`` 丢掉,于是设置卡上这些旋钮对会话路径完全不生效 —— 而且不报错。
|
|
926
930
|
这里把它们挪到唯一生效的位置。
|
|
927
931
|
|
|
@@ -1587,7 +1591,7 @@ def _make_session(kind: str, args: dict[str, Any]) -> Any:
|
|
|
1587
1591
|
from scrapling.fetchers import StealthySession
|
|
1588
1592
|
|
|
1589
1593
|
# 只有开场才生效的那些设置(block_ads / record_requests / headless / locale /
|
|
1590
|
-
# timezone_id / useragent / executable_path /
|
|
1594
|
+
# timezone_id / useragent / executable_path / timeout)必须在这里进会话:
|
|
1591
1595
|
# fetch 层传过去会被 validate_fetch 静默丢掉(见 FETCH_LEVEL_KEYS)。
|
|
1592
1596
|
common: dict[str, Any] = _session_browser_params(args)
|
|
1593
1597
|
# 每会话的记录开关:模型可以为这一次会话打开记录(部署侧那枚是默认值)。记录不改变
|
|
@@ -1804,7 +1808,7 @@ def session_fetch(args: dict[str, Any]) -> dict[str, Any]:
|
|
|
1804
1808
|
#
|
|
1805
1809
|
# level="fetch" 是这条路径的关键:会话内每次 fetch 只认 FETCH_LEVEL_KEYS,
|
|
1806
1810
|
# 其余键(block_ads / record_requests / headless / locale / timezone_id /
|
|
1807
|
-
# useragent / executable_path
|
|
1811
|
+
# useragent / executable_path,以及 hide_canvas / block_webrtc /
|
|
1808
1812
|
# allow_webgl)会被 validate_fetch **静默丢掉**。那些设置已经在 session.open
|
|
1809
1813
|
# 时经 _session_browser_params 进过会话了,这里再发一遍只会制造「拧了没反应」
|
|
1810
1814
|
# 的假象。
|
package/py/bridge.py
CHANGED
|
@@ -105,6 +105,10 @@ MAX_FRAME_BYTES = 8 * 1024 * 1024
|
|
|
105
105
|
# 所以正常情况下的深度约等于 MAX_INFLIGHT;超过它说明调用方在以远超并发的速率灌帧,
|
|
106
106
|
# 继续收就是纯粹的内存增长。判否让调用方自己退避。
|
|
107
107
|
MAX_QUEUE_DEPTH = MAX_INFLIGHT * 4
|
|
108
|
+
# 关机时每一路 close(爬虫、会话)的最长等待秒数。取 10 秒:浏览器会话的退出要给
|
|
109
|
+
# Chromium 进程留收尾时间,而 sidecar 自己已经不再服务任何请求,等更久只是把
|
|
110
|
+
# 「有界关机」变回无界。
|
|
111
|
+
SHUTDOWN_CLOSE_TIMEOUT = 10.0
|
|
108
112
|
|
|
109
113
|
_WRITE_LOCK = threading.Lock()
|
|
110
114
|
_SLOTS = threading.Semaphore(MAX_INFLIGHT)
|
|
@@ -300,6 +304,21 @@ def _ensure_worker(count: int) -> None:
|
|
|
300
304
|
worker.start()
|
|
301
305
|
|
|
302
306
|
|
|
307
|
+
def _run_bounded(label: str, action: Callable[[], None], timeout: float) -> None:
|
|
308
|
+
"""在后台线程里跑一次关闭并等它有界完成。
|
|
309
|
+
|
|
310
|
+
`close_all_crawls()` / `close_all_sessions()` 自己没有超时:它们要等 handler 释放
|
|
311
|
+
持有的锁,而那时 drain 已经放弃等待,关机就会从「有界」变成等一个不确定的对端。
|
|
312
|
+
超时后不重跑也不硬等——进程马上要退,这些资源由 OS 收;留一行日志是为了让宿主侧
|
|
313
|
+
读得出「这一轮是超时收的场」而不是「关干净了」。
|
|
314
|
+
"""
|
|
315
|
+
worker = threading.Thread(target=action, daemon=True, name=f"bridge-{label}")
|
|
316
|
+
worker.start()
|
|
317
|
+
worker.join(timeout)
|
|
318
|
+
if worker.is_alive():
|
|
319
|
+
log(f"shutdown: {label} still running after {timeout}s; leaving it to process exit")
|
|
320
|
+
|
|
321
|
+
|
|
303
322
|
def _shutdown_crawls() -> None:
|
|
304
323
|
"""退出前叫停全部爬虫,并给它们的线程一点收尾时间。
|
|
305
324
|
|
|
@@ -307,12 +326,16 @@ def _shutdown_crawls() -> None:
|
|
|
307
326
|
不读这一路了,帧落进管道就是没人认领的字节。所以爬虫要在会话之前关:蜘蛛自己也要用
|
|
308
327
|
浏览器,先把会话抽走只会让它在下一次请求里抛。
|
|
309
328
|
"""
|
|
310
|
-
try:
|
|
311
|
-
import crawl
|
|
312
329
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
330
|
+
def close() -> None:
|
|
331
|
+
try:
|
|
332
|
+
import crawl
|
|
333
|
+
|
|
334
|
+
crawl.close_all_crawls()
|
|
335
|
+
except Exception as error: # noqa: BLE001 —— 关不掉也不能拖住关机
|
|
336
|
+
log(f"failed to stop crawls: {type(error).__name__}: {error}")
|
|
337
|
+
|
|
338
|
+
_run_bounded("close-crawls", close, SHUTDOWN_CLOSE_TIMEOUT)
|
|
316
339
|
|
|
317
340
|
|
|
318
341
|
def _shutdown_sessions() -> None:
|
|
@@ -320,12 +343,16 @@ def _shutdown_sessions() -> None:
|
|
|
320
343
|
|
|
321
344
|
浏览器会话是独立进程:sidecar 自己退了、Chromium 还活着,就成了没人管的孤儿。
|
|
322
345
|
"""
|
|
323
|
-
try:
|
|
324
|
-
import adapters
|
|
325
346
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
347
|
+
def close() -> None:
|
|
348
|
+
try:
|
|
349
|
+
import adapters
|
|
350
|
+
|
|
351
|
+
adapters.close_all_sessions()
|
|
352
|
+
except Exception as error: # noqa: BLE001 —— 关不掉也不能拖住关机
|
|
353
|
+
log(f"failed to close sessions: {type(error).__name__}: {error}")
|
|
354
|
+
|
|
355
|
+
_run_bounded("close-sessions", close, SHUTDOWN_CLOSE_TIMEOUT)
|
|
329
356
|
|
|
330
357
|
|
|
331
358
|
def _drain_before_exit(timeout: float = 5.0) -> None:
|
|
@@ -333,20 +360,30 @@ def _drain_before_exit(timeout: float = 5.0) -> None:
|
|
|
333
360
|
|
|
334
361
|
收到 shutdown 就直接 return 的话,队列里已排队的请求会被静默丢掉 —— Host 侧看到的
|
|
335
362
|
是「没等到响应」而不是「被关机打断」。所以这里有界地等一下:等空了就走,等不到就
|
|
336
|
-
|
|
363
|
+
把还排着的帧逐条点名再走,不无限期拖住关机。
|
|
364
|
+
|
|
365
|
+
点名只覆盖队列里的帧:已经出队、正在 handler 里跑的请求没有一处集中的登记面,要命名
|
|
366
|
+
它们就得在 worker 的热路径上加簿记,这比一条关机日志不值。那一路的后果由
|
|
367
|
+
`_shutdown_crawls` / `_shutdown_sessions` 的有界关闭兜住(宿主侧等的是帧,不是关闭)。
|
|
337
368
|
|
|
338
369
|
:param timeout - 最长等待秒数
|
|
339
370
|
"""
|
|
340
371
|
deadline = time.monotonic() + timeout
|
|
341
|
-
while
|
|
372
|
+
while True:
|
|
342
373
|
with _QUEUE_LOCK:
|
|
343
|
-
pending =
|
|
374
|
+
pending = list(_QUEUE)
|
|
344
375
|
with _WORKERS_LOCK:
|
|
345
376
|
busy = any(item.is_alive() for item in _WORKERS)
|
|
346
377
|
if not pending and not busy:
|
|
347
378
|
return
|
|
379
|
+
if time.monotonic() >= deadline:
|
|
380
|
+
ids = [str(item.get("id", "(无 id)")) for item in pending]
|
|
381
|
+
log(
|
|
382
|
+
f"shutdown: giving up after {timeout}s — {len(ids)} 帧仍在队列里未应答 "
|
|
383
|
+
f"ids={','.join(ids) if ids else '(空)'}"
|
|
384
|
+
)
|
|
385
|
+
return
|
|
348
386
|
time.sleep(0.02)
|
|
349
|
-
log("shutdown: giving up on in-flight requests")
|
|
350
387
|
|
|
351
388
|
|
|
352
389
|
def read_loop() -> int:
|
package/py/extraction.py
CHANGED
|
@@ -62,8 +62,8 @@ def _resolve_url(page: Any, value: str) -> str:
|
|
|
62
62
|
return value
|
|
63
63
|
|
|
64
64
|
|
|
65
|
-
def _query_type(
|
|
66
|
-
"""把旧的 ``useXpath`` 布尔值归一到 queryType。"""
|
|
65
|
+
def _query_type(query_type: str | None, use_xpath: bool) -> str:
|
|
66
|
+
"""把旧的 ``useXpath`` 布尔值归一到 queryType:显式 queryType 优先,其次 useXpath,最后 css。"""
|
|
67
67
|
return query_type or ("xpath" if use_xpath else "css")
|
|
68
68
|
|
|
69
69
|
|
|
@@ -86,7 +86,7 @@ def query_nodes(
|
|
|
86
86
|
"""
|
|
87
87
|
if not isinstance(selector, str) or not selector:
|
|
88
88
|
raise ValueError("selector is required")
|
|
89
|
-
kind = _query_type(
|
|
89
|
+
kind = _query_type(query_type, use_xpath)
|
|
90
90
|
if kind == "css":
|
|
91
91
|
return list(page.css(selector)), ""
|
|
92
92
|
if kind == "xpath":
|