papersearch 0.7.3 → 0.8.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/LICENSE-paper-search-mcp-nodejs +24 -0
- package/NOTICE +8 -37
- package/README.en.md +7 -3
- package/README.fr.md +268 -0
- package/README.ja.md +268 -0
- package/README.ko.md +268 -0
- package/README.md +7 -3
- package/README.zh-Hant.md +268 -0
- package/dist/capabilities/download/batch/batch.d.ts +16 -1
- package/dist/capabilities/download/batch/batch.d.ts.map +1 -1
- package/dist/capabilities/download/batch/batch.js +389 -56
- package/dist/capabilities/download/batch/batch.js.map +1 -1
- package/dist/capabilities/download/batch/batchFolder.d.ts.map +1 -1
- package/dist/capabilities/download/batch/batchFolder.js +3 -2
- package/dist/capabilities/download/batch/batchFolder.js.map +1 -1
- package/dist/capabilities/download/batch/networkLoss.d.ts +11 -2
- package/dist/capabilities/download/batch/networkLoss.d.ts.map +1 -1
- package/dist/capabilities/download/batch/networkLoss.js +24 -3
- package/dist/capabilities/download/batch/networkLoss.js.map +1 -1
- package/dist/capabilities/download/batch/resume.d.ts +7 -0
- package/dist/capabilities/download/batch/resume.d.ts.map +1 -1
- package/dist/capabilities/download/batch/resume.js +50 -9
- package/dist/capabilities/download/batch/resume.js.map +1 -1
- package/dist/capabilities/download/content/markdown/pro.d.ts +6 -0
- package/dist/capabilities/download/content/markdown/pro.d.ts.map +1 -1
- package/dist/capabilities/download/content/markdown/pro.js.map +1 -1
- package/dist/capabilities/download/content/markdown/shortfall.d.ts +8 -5
- package/dist/capabilities/download/content/markdown/shortfall.d.ts.map +1 -1
- package/dist/capabilities/download/content/markdown/shortfall.js +22 -10
- package/dist/capabilities/download/content/markdown/shortfall.js.map +1 -1
- package/dist/capabilities/download/content/markdown/step.d.ts +9 -0
- package/dist/capabilities/download/content/markdown/step.d.ts.map +1 -1
- package/dist/capabilities/download/content/markdown/step.js +42 -2
- package/dist/capabilities/download/content/markdown/step.js.map +1 -1
- package/dist/capabilities/download/content/markdown/types.d.ts +10 -1
- package/dist/capabilities/download/content/markdown/types.d.ts.map +1 -1
- package/dist/capabilities/download/handler.d.ts.map +1 -1
- package/dist/capabilities/download/handler.js +13 -5
- package/dist/capabilities/download/handler.js.map +1 -1
- package/dist/capabilities/download/outputLayout.d.ts.map +1 -1
- package/dist/capabilities/download/outputLayout.js +3 -1
- package/dist/capabilities/download/outputLayout.js.map +1 -1
- package/dist/capabilities/download/tools.js +2 -2
- package/dist/capabilities/download/tools.js.map +1 -1
- package/dist/capabilities/download/types.d.ts +9 -1
- package/dist/capabilities/download/types.d.ts.map +1 -1
- package/dist/cli.js +3 -1
- package/dist/cli.js.map +1 -1
- package/dist/infrastructure/runlog/RunLedger.d.ts +7 -0
- package/dist/infrastructure/runlog/RunLedger.d.ts.map +1 -1
- package/dist/infrastructure/runlog/RunLedger.js +13 -0
- package/dist/infrastructure/runlog/RunLedger.js.map +1 -1
- package/dist/infrastructure/runlog/failureClass.d.ts +2 -1
- package/dist/infrastructure/runlog/failureClass.d.ts.map +1 -1
- package/dist/infrastructure/runlog/failureClass.js +27 -4
- package/dist/infrastructure/runlog/failureClass.js.map +1 -1
- package/dist/infrastructure/school/SchoolAttempt.d.ts +11 -0
- package/dist/infrastructure/school/SchoolAttempt.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolAttempt.js +48 -5
- package/dist/infrastructure/school/SchoolAttempt.js.map +1 -1
- package/dist/infrastructure/school/SchoolMcpClient.d.ts +1 -0
- package/dist/infrastructure/school/SchoolMcpClient.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolMcpClient.js +18 -6
- package/dist/infrastructure/school/SchoolMcpClient.js.map +1 -1
- package/dist/infrastructure/school/SchoolProgress.d.ts +2 -0
- package/dist/infrastructure/school/SchoolProgress.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolProgress.js +2 -0
- package/dist/infrastructure/school/SchoolProgress.js.map +1 -1
- package/dist/infrastructure/school/SchoolReadiness.d.ts +2 -0
- package/dist/infrastructure/school/SchoolReadiness.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolReadiness.js +2 -0
- package/dist/infrastructure/school/SchoolReadiness.js.map +1 -1
- package/dist/infrastructure/school/SchoolResultNormalizer.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolResultNormalizer.js +4 -0
- package/dist/infrastructure/school/SchoolResultNormalizer.js.map +1 -1
- package/dist/infrastructure/school/index.d.ts +2 -2
- package/dist/infrastructure/school/index.d.ts.map +1 -1
- package/dist/infrastructure/school/index.js +1 -1
- package/dist/infrastructure/school/index.js.map +1 -1
- package/dist/infrastructure/school/types.d.ts +42 -0
- package/dist/infrastructure/school/types.d.ts.map +1 -1
- package/dist/infrastructure/school/types.js.map +1 -1
- package/dist/management/failures/index.d.ts +23 -0
- package/dist/management/failures/index.d.ts.map +1 -1
- package/dist/management/failures/index.js +63 -18
- package/dist/management/failures/index.js.map +1 -1
- package/package.json +7 -2
- package/school/NOTICE +3 -2
- package/school/paper_search_school/adapters/__init__.py +2 -0
- package/school/paper_search_school/adapters/aps/__init__.py +3 -6
- package/school/paper_search_school/adapters/base.py +16 -2
- package/school/paper_search_school/adapters/copernicus/__init__.py +2 -7
- package/school/paper_search_school/adapters/elsevier/__init__.py +50 -1
- package/school/paper_search_school/adapters/frontiers/__init__.py +41 -2
- package/school/paper_search_school/adapters/ieee/__init__.py +6 -4
- package/school/paper_search_school/adapters/iop/__init__.py +8 -0
- package/school/paper_search_school/adapters/jama/__init__.py +8 -0
- package/school/paper_search_school/adapters/lww/__init__.py +14 -6
- package/school/paper_search_school/adapters/mdpi/__init__.py +12 -7
- package/school/paper_search_school/adapters/neurology/__init__.py +5 -2
- package/school/paper_search_school/adapters/optica/__init__.py +2 -9
- package/school/paper_search_school/adapters/oup/__init__.py +7 -4
- package/school/paper_search_school/adapters/platforms/__init__.py +4 -1
- package/school/paper_search_school/adapters/platforms/atypon/__init__.py +8 -0
- package/school/paper_search_school/adapters/platforms/jstage/__init__.py +64 -0
- package/school/paper_search_school/adapters/taylor_francis/__init__.py +0 -3
- package/school/paper_search_school/adapters/thieme/__init__.py +2 -9
- package/school/paper_search_school/api_keys.py +63 -13
- package/school/paper_search_school/assets/api_keys.json +14 -0
- package/school/paper_search_school/assets/capsule.html +156 -116
- package/school/paper_search_school/assets/capsule_en.json +69 -46
- package/school/paper_search_school/assets/capsule_fr.json +70 -47
- package/school/paper_search_school/assets/capsule_ja.json +69 -46
- package/school/paper_search_school/assets/capsule_ko.json +69 -46
- package/school/paper_search_school/assets/capsule_zh-Hant.json +68 -45
- package/school/paper_search_school/browser/batch_session.py +1 -1
- package/school/paper_search_school/browser/challenge/__init__.py +12 -9
- package/school/paper_search_school/browser/challenge/continuation.py +65 -0
- package/school/paper_search_school/browser/challenge/handlers/__init__.py +1 -0
- package/school/paper_search_school/browser/challenge/handlers/aws_waf.py +260 -0
- package/school/paper_search_school/browser/challenge/handlers/recaptcha_hcaptcha.py +167 -0
- package/school/paper_search_school/browser/challenge/handlers/text_captcha.py +100 -0
- package/school/paper_search_school/browser/challenge/handlers/turnstile.py +174 -0
- package/school/paper_search_school/browser/challenge/kinds.py +203 -0
- package/school/paper_search_school/browser/challenge/local/__init__.py +1 -0
- package/school/paper_search_school/browser/challenge/{interaction.py → local/interaction.py} +94 -13
- package/school/paper_search_school/browser/challenge/{pointer.py → local/pointer.py} +2 -2
- package/school/paper_search_school/browser/challenge/local/prompt.py +283 -0
- package/school/paper_search_school/browser/challenge/local/submission.py +33 -0
- package/school/paper_search_school/browser/challenge/services/__init__.py +1 -0
- package/school/paper_search_school/browser/challenge/services/solver.py +272 -0
- package/school/paper_search_school/cli_config.py +10 -5
- package/school/paper_search_school/config.py +11 -10
- package/school/paper_search_school/download_diagnostics.py +7 -2
- package/school/paper_search_school/engine/access_rules.py +12 -3
- package/school/paper_search_school/engine/batch.py +43 -11
- package/school/paper_search_school/engine/batch_access.py +38 -12
- package/school/paper_search_school/engine/batch_capture.py +215 -18
- package/school/paper_search_school/engine/batch_common.py +3 -0
- package/school/paper_search_school/engine/batch_diagnostics.py +25 -5
- package/school/paper_search_school/engine/batch_institution.py +38 -3
- package/school/paper_search_school/engine/batch_login.py +223 -16
- package/school/paper_search_school/engine/batch_pdf_urls.py +38 -7
- package/school/paper_search_school/engine/batch_waits.py +179 -12
- package/school/paper_search_school/engine/bridge.py +28 -4
- package/school/paper_search_school/engine/fulltext_page.py +45 -7
- package/school/paper_search_school/engine/router.py +16 -1
- package/school/paper_search_school/entitlements.py +1 -1
- package/school/paper_search_school/pdf_utils.py +25 -16
- package/school/paper_search_school/progress_capsule.py +36 -6
- package/school/paper_search_school/progress_reporter.py +54 -5
- package/school/paper_search_school/progress_view.py +63 -43
- package/school/paper_search_school/publishers/builtin/iop.json +2 -1
- package/school/paper_search_school/publishers/builtin/neurology.json +4 -2
- package/school/paper_search_school/publishers/site.py +12 -4
- package/school/paper_search_school/school_test.py +1 -1
- package/school/paper_search_school/server.py +17 -6
- package/school/paper_search_school/user_settings.py +13 -0
- package/school/pyproject.toml +1 -0
- package/skills/paper-search/SKILL.md +107 -107
- package/skills/paper-search/references/browser-download.md +102 -99
- package/skills/paper-search/references/capability-routing.md +89 -89
- package/skills/paper-search/references/cli-contract.md +78 -78
- package/skills/paper-search/references/federation-support.md +172 -172
- package/skills/paper-search/references/management-layer.md +78 -78
- package/skills/paper-search/references/publisher-support.md +38 -38
- package/skills/paper-search/references/school-setup.md +56 -55
- package/skills/paper-search/references/setup.md +20 -20
- package/skills/paper-search/references/troubleshooting.md +12 -12
- package/school/paper_search_school/browser/challenge/prompt.py +0 -154
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"""Standalone Turnstile tokens delivered to the original widget and its form."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import ipaddress
|
|
5
|
+
import re
|
|
6
|
+
from contextlib import ExitStack
|
|
7
|
+
from typing import Any
|
|
8
|
+
from urllib.parse import urlsplit
|
|
9
|
+
|
|
10
|
+
from ...driver import Error, main_world
|
|
11
|
+
from ...watchdog import CallAbandoned, call_limit
|
|
12
|
+
from ..local import submission
|
|
13
|
+
from ..services import solver
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
_INSPECT = r'''(empty = true) => {
|
|
17
|
+
const shown = el => el.getClientRects().length > 0 && getComputedStyle(el).visibility !== 'hidden';
|
|
18
|
+
if ((document.body?.innerText || '').length > 2500 || window._cf_chl_opt ||
|
|
19
|
+
/__cf_chl|\/cdn-cgi\/challenge-platform\//i.test(location.href) ||
|
|
20
|
+
/^(just a moment|请稍候|attention required|checking your browser)/i.test(document.title) ||
|
|
21
|
+
document.querySelector('#challenge-form,#challenge-stage,meta[name="citation_doi"],meta[name="citation_title"]') ||
|
|
22
|
+
[...document.querySelectorAll('input[type=password],input[type=email]')].some(shown)) return null;
|
|
23
|
+
const widgets = [...document.querySelectorAll('.cf-turnstile[data-sitekey]')].filter(shown);
|
|
24
|
+
if (widgets.length !== 1) return null;
|
|
25
|
+
const widget = widgets[0], sitekey = widget.dataset.sitekey || '', action = widget.dataset.action || '';
|
|
26
|
+
if (!/^0x[A-Za-z0-9_-]{10,100}$/.test(sitekey) || (action && !/^[A-Za-z0-9_-]{1,32}$/.test(action)) ||
|
|
27
|
+
widget.dataset.cdata || widget.dataset.chlPageData) return null;
|
|
28
|
+
const name = widget.dataset.responseFieldName || 'cf-turnstile-response';
|
|
29
|
+
const fields = [...widget.querySelectorAll('input,textarea')].filter(el=>el.name===name);
|
|
30
|
+
if (fields.length > 1) return null;
|
|
31
|
+
const field = fields[0] || null;
|
|
32
|
+
if (field && (field.disabled || (empty && field.value))) return null;
|
|
33
|
+
let callback = null, owner = window;
|
|
34
|
+
const path = widget.dataset.callback || '';
|
|
35
|
+
if (path) {
|
|
36
|
+
if (!/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/.test(path)) return null;
|
|
37
|
+
const parts = path.split('.');
|
|
38
|
+
for (const part of parts.slice(0,-1)) { owner=owner?.[part]; if(!owner)return null; }
|
|
39
|
+
callback=owner[parts.at(-1)];
|
|
40
|
+
if (typeof callback !== 'function') return null;
|
|
41
|
+
}
|
|
42
|
+
const form = field?.form || widget.closest('form');
|
|
43
|
+
if (form && [...form.querySelectorAll('input,textarea,select,[contenteditable=true]')]
|
|
44
|
+
.some(el=>el!==field && shown(el) && !['hidden','submit','image','button','reset'].includes(el.type))) return null;
|
|
45
|
+
const buttons = form ? (''' + submission.CANDIDATES + r''')(form,form) : [];
|
|
46
|
+
if (buttons.length > 1 || (!callback && (!field || buttons.length !== 1))) return null;
|
|
47
|
+
const events = window[Symbol.for('papersearch.turnstile.events')] || [];
|
|
48
|
+
return {widget,field,form,submit:buttons[0] || null,callback,owner,
|
|
49
|
+
frames:[...widget.querySelectorAll('iframe')],
|
|
50
|
+
meta:{sitekey,action,name,path,url:location.href,
|
|
51
|
+
frames:[...widget.querySelectorAll('iframe')].map(el=>el.src),
|
|
52
|
+
revision:events.length ? [events.length,events.at(-1).event,events.at(-1).at] : null}};
|
|
53
|
+
}'''
|
|
54
|
+
|
|
55
|
+
_CURRENT = r'''old => {
|
|
56
|
+
const now = (''' + _INSPECT + r''')(false);
|
|
57
|
+
return !!now && ['widget','field','form','submit','callback','owner'].every(k=>now[k]===old[k]) &&
|
|
58
|
+
now.frames.length===old.frames.length && now.frames.every((frame,i)=>frame===old.frames[i]) &&
|
|
59
|
+
JSON.stringify(now.meta)===JSON.stringify(old.meta);
|
|
60
|
+
}'''
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def public_origin(url: str) -> str:
|
|
64
|
+
"""Drop paths and queries, which can contain publisher or school sessions."""
|
|
65
|
+
try:
|
|
66
|
+
parsed = urlsplit(url)
|
|
67
|
+
host = parsed.hostname or ""
|
|
68
|
+
if (parsed.scheme != "https" or parsed.username or parsed.password or "." not in host
|
|
69
|
+
or host.endswith((".localhost", ".local", ".internal"))):
|
|
70
|
+
return ""
|
|
71
|
+
try:
|
|
72
|
+
if not ipaddress.ip_address(host).is_global:
|
|
73
|
+
return ""
|
|
74
|
+
except ValueError:
|
|
75
|
+
pass # a DNS name
|
|
76
|
+
return f"https://{parsed.netloc}/"
|
|
77
|
+
except ValueError:
|
|
78
|
+
return ""
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _user_agent(page: Any, origin: str, agent: str, cleanup: ExitStack, note: Any = None) -> None:
|
|
82
|
+
"""Use the service UA on this page's origin requests until the wait ends."""
|
|
83
|
+
pattern = re.compile("^" + re.escape(origin))
|
|
84
|
+
|
|
85
|
+
def forward(route: Any) -> None:
|
|
86
|
+
route.fallback(headers={**route.request.headers, "user-agent": agent})
|
|
87
|
+
|
|
88
|
+
page.route(pattern, forward)
|
|
89
|
+
|
|
90
|
+
def release() -> None:
|
|
91
|
+
try:
|
|
92
|
+
if not page.is_closed():
|
|
93
|
+
page.unroute(pattern, forward)
|
|
94
|
+
except Error:
|
|
95
|
+
if note:
|
|
96
|
+
note('turnstile: browser unavailable during request-route cleanup')
|
|
97
|
+
|
|
98
|
+
cleanup.callback(release)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _apply(page: Any, snapshot: Any, token: str, limits: Any, note: Any) -> bool:
|
|
102
|
+
limits.remaining()
|
|
103
|
+
if not snapshot.evaluate(_CURRENT, **main_world(snapshot)):
|
|
104
|
+
note('turnstile: widget changed; discard answer')
|
|
105
|
+
return False
|
|
106
|
+
applied = snapshot.evaluate(r'''(s,token) => {
|
|
107
|
+
if (s.field?.value) return false;
|
|
108
|
+
if (s.field) {
|
|
109
|
+
const prototype = s.field.tagName==='TEXTAREA' ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
|
|
110
|
+
Object.getOwnPropertyDescriptor(prototype,'value').set.call(s.field,token);
|
|
111
|
+
s.field.dispatchEvent(new Event('input',{bubbles:true}));
|
|
112
|
+
s.field.dispatchEvent(new Event('change',{bubbles:true}));
|
|
113
|
+
}
|
|
114
|
+
if (s.callback) Reflect.apply(s.callback,s.owner,[token]);
|
|
115
|
+
return true;
|
|
116
|
+
}''', token, **main_world(snapshot))
|
|
117
|
+
if not applied:
|
|
118
|
+
note('turnstile: local answer already present; discard service answer')
|
|
119
|
+
return False
|
|
120
|
+
note('turnstile: response delivered; awaiting page verification')
|
|
121
|
+
limits.remaining()
|
|
122
|
+
if snapshot.evaluate(_CURRENT, **main_world(snapshot)):
|
|
123
|
+
control = snapshot.get_property('submit').as_element()
|
|
124
|
+
if control is not None:
|
|
125
|
+
control.click(timeout=min(3000, int(limits.remaining()*1000)), no_wait_after=True)
|
|
126
|
+
note('turnstile: form submitted; awaiting page verification')
|
|
127
|
+
return True
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def solve(page: Any, config: dict, *, limits: Any, observation: Any) -> bool:
|
|
131
|
+
"""Delivery requests another outer page check; it never proves access."""
|
|
132
|
+
note = observation
|
|
133
|
+
origin = public_origin(str(page.url or ""))
|
|
134
|
+
if not origin:
|
|
135
|
+
note('turnstile: no public HTTPS origin')
|
|
136
|
+
return False
|
|
137
|
+
snapshot = None
|
|
138
|
+
with ExitStack() as owned:
|
|
139
|
+
cleanup = limits.cleanup if limits.cleanup is not None else owned
|
|
140
|
+
try:
|
|
141
|
+
with call_limit(min(5, limits.remaining())):
|
|
142
|
+
snapshot = page.evaluate_handle(_INSPECT, True, **main_world(page))
|
|
143
|
+
metadata = snapshot.evaluate('s=>s?.meta || null', **main_world(snapshot))
|
|
144
|
+
if not metadata:
|
|
145
|
+
note('turnstile: unsupported or ambiguous widget/continuation')
|
|
146
|
+
return False
|
|
147
|
+
if not limits.budget.take():
|
|
148
|
+
note('service budget exhausted')
|
|
149
|
+
return False
|
|
150
|
+
answer = solver.solve_turnstile(origin, metadata['sitekey'], config,
|
|
151
|
+
action=metadata['action'], timeout=limits.remaining(),
|
|
152
|
+
checkpoint=limits.remaining)
|
|
153
|
+
limits.remaining()
|
|
154
|
+
if answer is None:
|
|
155
|
+
note('turnstile: service did not return a valid token and User-Agent')
|
|
156
|
+
return False
|
|
157
|
+
_user_agent(page, origin, answer.user_agent, cleanup, note)
|
|
158
|
+
with call_limit(min(5, limits.remaining())):
|
|
159
|
+
delivered = _apply(page, snapshot, answer.token, limits, note)
|
|
160
|
+
if delivered:
|
|
161
|
+
page.wait_for_timeout(min(250, int(limits.remaining()*1000)))
|
|
162
|
+
return delivered
|
|
163
|
+
except CallAbandoned:
|
|
164
|
+
note('turnstile: browser call timed out; recheck page')
|
|
165
|
+
return False
|
|
166
|
+
except Error:
|
|
167
|
+
note('turnstile: page changed or action failed; recheck page')
|
|
168
|
+
return False
|
|
169
|
+
finally:
|
|
170
|
+
if snapshot is not None:
|
|
171
|
+
try:
|
|
172
|
+
snapshot.dispose()
|
|
173
|
+
except Error:
|
|
174
|
+
pass # navigation can destroy the original execution context
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"""Which kind of verification a verification page is, for the record only.
|
|
2
|
+
|
|
3
|
+
The user (2026-11-25): a paper stopped by a site's verification should say which
|
|
4
|
+
kind stopped it. This module only names the kind: it never clicks, waits, hands a
|
|
5
|
+
page over or decides anything about the wait (``local.interaction.challenge_kind`` is
|
|
6
|
+
the handoff's own reading and stays as it is).
|
|
7
|
+
|
|
8
|
+
``read`` takes one look at the page (its address, title, frames, scripts and a few
|
|
9
|
+
elements, in one script call); ``classify`` names the kind from that look, without
|
|
10
|
+
the browser. A page whose title or address already says Cloudflare's interstitial
|
|
11
|
+
is not read further: reading an active check can disturb it (``detection``).
|
|
12
|
+
"""
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import re
|
|
16
|
+
from typing import Any
|
|
17
|
+
from urllib.parse import urlsplit
|
|
18
|
+
|
|
19
|
+
#: Each kind and how the record and messages name it (the user's list, 2026-11-25),
|
|
20
|
+
#: then the other providers the program knows, then a verification page of no
|
|
21
|
+
#: kind told. The keys are a fixed vocabulary (the CLI keeps only these).
|
|
22
|
+
LABELS: dict[str, str] = {
|
|
23
|
+
"recaptcha_v2": "reCAPTCHA v2",
|
|
24
|
+
"recaptcha_v3": "reCAPTCHA v3",
|
|
25
|
+
"hcaptcha": "hCaptcha",
|
|
26
|
+
"cloudflare": "Cloudflare 5 秒盾",
|
|
27
|
+
"image_code": "图片英数字识别",
|
|
28
|
+
"recaptcha_v2_image": "reCAPTCHA v2 图像识别",
|
|
29
|
+
"hcaptcha_image": "hCaptcha 图像识别",
|
|
30
|
+
"funcaptcha_image": "FunCaptcha 图像识别",
|
|
31
|
+
"awswaf_image": "AWS WAF / bCaptcha 图像识别",
|
|
32
|
+
"turnstile": "Cloudflare Turnstile",
|
|
33
|
+
"friendly_captcha": "Friendly Captcha",
|
|
34
|
+
"geetest": "GeeTest",
|
|
35
|
+
"datadome": "DataDome",
|
|
36
|
+
"perimeterx": "PerimeterX",
|
|
37
|
+
"aliyun": "阿里云验证码",
|
|
38
|
+
"tencent": "腾讯验证码",
|
|
39
|
+
"other": "其他验证(未分出类型)",
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
_RECAPTCHA_HOSTS = {"www.google.com", "google.com", "www.recaptcha.net", "recaptcha.net"}
|
|
43
|
+
_RECAPTCHA_FRAME = re.compile(r"^/recaptcha/(?:api2|enterprise)/(anchor|bframe)")
|
|
44
|
+
_RECAPTCHA_SCRIPT = re.compile(r"/recaptcha/(?:api|enterprise)\.js\b")
|
|
45
|
+
_CLOUDFLARE_TITLES = ("just a moment", "请稍候", "attention required", "checking your browser",
|
|
46
|
+
"verifying you are human")
|
|
47
|
+
_ARKOSE = re.compile(r"(?:^|\.)(?:arkoselabs\.com|funcaptcha\.com)$")
|
|
48
|
+
_DATADOME = re.compile(r"(?:^|\.)captcha-delivery\.com$")
|
|
49
|
+
_TENCENT_HOSTS = {"turing.captcha.qcloud.com", "t.captcha.qq.com", "ssl.captcha.qq.com"}
|
|
50
|
+
|
|
51
|
+
# One look at the page: every iframe's address and whether it is shown, the scripts'
|
|
52
|
+
# addresses, and the elements a kind is told by. Shown: on the page, not hidden by
|
|
53
|
+
# CSS (reCAPTCHA keeps its picture frame at top -10000 px, hCaptcha behind
|
|
54
|
+
# visibility: hidden, until the puzzle is asked).
|
|
55
|
+
_READ_JS = r"""() => {
|
|
56
|
+
const shown = el => {
|
|
57
|
+
if (!el) return false;
|
|
58
|
+
const r = el.getBoundingClientRect();
|
|
59
|
+
if (r.width < 2 || r.height < 2 || r.bottom <= 0 || r.right <= 0) return false;
|
|
60
|
+
return typeof el.checkVisibility === 'function'
|
|
61
|
+
? el.checkVisibility({checkOpacity: true, checkVisibilityCSS: true}) : true;
|
|
62
|
+
};
|
|
63
|
+
const any = selector => [...document.querySelectorAll(selector)].some(shown);
|
|
64
|
+
const marker = /captcha|verif(?:y|ication)[-_ ]?code|validat(?:e|ion)[-_ ]?code|check[-_ ]?code|验证码/i;
|
|
65
|
+
const provider = /recaptcha|hcaptcha|arkoselabs|funcaptcha|awswaf|geetest|turnstile|cloudflare/i;
|
|
66
|
+
const codeImage = [...document.querySelectorAll('img, canvas')].some(el => shown(el)
|
|
67
|
+
&& marker.test([el.id, el.className, el.getAttribute('src'), el.getAttribute('alt'), el.getAttribute('name')].join(' '))
|
|
68
|
+
&& !provider.test(el.getAttribute('src') || ''));
|
|
69
|
+
const typing = [...document.querySelectorAll('input')].some(el => shown(el) && !el.disabled
|
|
70
|
+
&& (!el.type || ['text', 'tel', 'number', 'search'].includes(el.type)));
|
|
71
|
+
return {
|
|
72
|
+
frames: [...document.querySelectorAll('iframe')].map(f => ({src: f.src || '', shown: shown(f)})),
|
|
73
|
+
scripts: [...document.scripts].map(s => s.src || '').filter(Boolean).slice(0, 200),
|
|
74
|
+
image_code: codeImage && typing,
|
|
75
|
+
awswaf: !!document.querySelector('awswaf-captcha, #amzn-captcha-container, .amzn-captcha-root, #amzn-captcha-verify-button'),
|
|
76
|
+
cloudflare: !!document.querySelector('#challenge-form, #challenge-stage, #challenge-running, #cf-challenge-running, #challenge-body-text'),
|
|
77
|
+
recaptcha_badge: !!document.querySelector('.grecaptcha-badge'),
|
|
78
|
+
friendly_captcha: any('.frc-captcha'),
|
|
79
|
+
geetest: any('.geetest_holder, .geetest_panel, .geetest_box, .geetest_captcha'),
|
|
80
|
+
aliyun: any("[id^='aliyunCaptcha-'], #nc_1_wrapper"),
|
|
81
|
+
tencent: any('#tcaptcha_iframe, #tcaptcha_transform'),
|
|
82
|
+
perimeterx: any('#px-captcha'),
|
|
83
|
+
};
|
|
84
|
+
}"""
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _host(url: str) -> str:
|
|
88
|
+
try:
|
|
89
|
+
return (urlsplit(url).hostname or "").lower()
|
|
90
|
+
except ValueError:
|
|
91
|
+
return ""
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _recaptcha_frame(url: str) -> str:
|
|
95
|
+
""""anchor" (the box; "invisible" for v3's), "bframe" (the picture puzzle) or ""."""
|
|
96
|
+
parts = urlsplit(url)
|
|
97
|
+
if parts.scheme != "https" or (parts.hostname or "").lower() not in _RECAPTCHA_HOSTS:
|
|
98
|
+
return ""
|
|
99
|
+
match = _RECAPTCHA_FRAME.match(parts.path)
|
|
100
|
+
if not match:
|
|
101
|
+
return ""
|
|
102
|
+
if match[1] == "anchor" and re.search(r"(?:^|&)size=invisible(?:&|$)", parts.query):
|
|
103
|
+
return "invisible"
|
|
104
|
+
return match[1]
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _hcaptcha_frame(url: str) -> str:
|
|
108
|
+
""""checkbox", "challenge" (the picture puzzle) or ""."""
|
|
109
|
+
host = _host(url)
|
|
110
|
+
if not (host == "hcaptcha.com" or host.endswith(".hcaptcha.com")) or "/captcha/" not in url:
|
|
111
|
+
return ""
|
|
112
|
+
found = re.search(r"[#&?]frame=(checkbox|challenge)\b", url)
|
|
113
|
+
return found[1] if found else ""
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _turnstile_frame(url: str) -> bool:
|
|
117
|
+
return _host(url) == "challenges.cloudflare.com" and "/turnstile/" in url
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def classify(seen: dict[str, Any]) -> str:
|
|
121
|
+
"""The kind (a key of ``LABELS``) of the verification page ``seen`` describes:
|
|
122
|
+
``url``, ``title``, ``frames`` ([{src, shown}] of its iframes), ``page_frames``
|
|
123
|
+
(every frame's address, nested ones too), ``scripts`` and the element flags of
|
|
124
|
+
``_READ_JS``. A puzzle that is up counts before its box, the box before
|
|
125
|
+
Cloudflare's page, and an invisible check (reCAPTCHA v3) only when nothing
|
|
126
|
+
else is there."""
|
|
127
|
+
url = str(seen.get("url") or "")
|
|
128
|
+
title = str(seen.get("title") or "").strip().lower()
|
|
129
|
+
frames = [f for f in seen.get("frames") or () if isinstance(f, dict)]
|
|
130
|
+
page_frames = [str(u) for u in seen.get("page_frames") or ()]
|
|
131
|
+
scripts = [str(s) for s in seen.get("scripts") or ()]
|
|
132
|
+
shown = [str(f.get("src") or "") for f in frames if f.get("shown") is True]
|
|
133
|
+
every = [str(f.get("src") or "") for f in frames] + page_frames
|
|
134
|
+
|
|
135
|
+
if any(_recaptcha_frame(src) == "bframe" for src in shown):
|
|
136
|
+
return "recaptcha_v2_image"
|
|
137
|
+
if any(_hcaptcha_frame(src) == "challenge" for src in shown):
|
|
138
|
+
return "hcaptcha_image"
|
|
139
|
+
if (any(_ARKOSE.search(_host(src)) for src in every)
|
|
140
|
+
or any(_ARKOSE.search(_host(src)) for src in scripts)):
|
|
141
|
+
return "funcaptcha_image"
|
|
142
|
+
if seen.get("awswaf") or any(_host(src).endswith(".captcha.awswaf.com") for src in scripts + every):
|
|
143
|
+
return "awswaf_image"
|
|
144
|
+
if any(_recaptcha_frame(src) == "anchor" for src in shown):
|
|
145
|
+
return "recaptcha_v2"
|
|
146
|
+
if any(_hcaptcha_frame(src) == "checkbox" for src in shown):
|
|
147
|
+
return "hcaptcha"
|
|
148
|
+
if ("__cf_chl" in url or "/cdn-cgi/challenge-platform/" in url or title.startswith(_CLOUDFLARE_TITLES)
|
|
149
|
+
or seen.get("cloudflare") or any("/cdn-cgi/challenge-platform/" in src for src in scripts)):
|
|
150
|
+
return "cloudflare"
|
|
151
|
+
if any(_turnstile_frame(src) for src in shown):
|
|
152
|
+
return "turnstile"
|
|
153
|
+
if seen.get("image_code"):
|
|
154
|
+
return "image_code"
|
|
155
|
+
for key in ("friendly_captcha", "geetest", "aliyun", "tencent", "perimeterx"):
|
|
156
|
+
if seen.get(key):
|
|
157
|
+
return key
|
|
158
|
+
if any("frcapi.com/api/v2/captcha/widget" in src for src in shown):
|
|
159
|
+
return "friendly_captcha"
|
|
160
|
+
if any(_DATADOME.search(_host(src)) for src in every):
|
|
161
|
+
return "datadome"
|
|
162
|
+
if any(_host(src) in _TENCENT_HOSTS for src in every):
|
|
163
|
+
return "tencent"
|
|
164
|
+
if (any(_recaptcha_frame(src) == "invisible" for src in every) or seen.get("recaptcha_badge")
|
|
165
|
+
or any(_RECAPTCHA_SCRIPT.search(src) and re.search(r"[?&]render=(?!explicit\b)[^&]+", src)
|
|
166
|
+
for src in scripts)):
|
|
167
|
+
return "recaptcha_v3"
|
|
168
|
+
return "other"
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def read(page: Any, *, title_and_url_only: bool = False) -> dict[str, Any]:
|
|
172
|
+
"""One look at ``page`` for ``classify``. What cannot be read (the page moved on
|
|
173
|
+
or closed meanwhile, or did not answer within the read limit) is left out."""
|
|
174
|
+
from ..driver import Error
|
|
175
|
+
from ..watchdog import CallAbandoned, call_limit
|
|
176
|
+
from .local.interaction import READ_LIMIT_SEC
|
|
177
|
+
|
|
178
|
+
seen: dict[str, Any] = {}
|
|
179
|
+
try:
|
|
180
|
+
seen["url"] = str(getattr(page, "url", "") or "")
|
|
181
|
+
with call_limit(READ_LIMIT_SEC):
|
|
182
|
+
seen["title"] = str(page.title() or "")
|
|
183
|
+
except (Error, CallAbandoned):
|
|
184
|
+
pass
|
|
185
|
+
if title_and_url_only:
|
|
186
|
+
return seen
|
|
187
|
+
try:
|
|
188
|
+
with call_limit(READ_LIMIT_SEC):
|
|
189
|
+
found = page.evaluate(_READ_JS)
|
|
190
|
+
if isinstance(found, dict):
|
|
191
|
+
seen.update(found)
|
|
192
|
+
except (Error, CallAbandoned):
|
|
193
|
+
pass
|
|
194
|
+
try:
|
|
195
|
+
seen["page_frames"] = [str(getattr(frame, "url", "") or "") for frame in list(page.frames)[:50]]
|
|
196
|
+
except (Error, CallAbandoned):
|
|
197
|
+
pass
|
|
198
|
+
return seen
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def identify(page: Any, *, title_and_url_only: bool = False) -> str:
|
|
202
|
+
"""The kind of the verification page ``page`` shows (a key of ``LABELS``)."""
|
|
203
|
+
return classify(read(page, title_and_url_only=title_and_url_only))
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Local browser controls, including Cloudflare/Turnstile clicks."""
|
package/school/paper_search_school/browser/challenge/{interaction.py → local/interaction.py}
RENAMED
|
@@ -32,7 +32,7 @@ _OBSERVE_SCRIPT = """() => {
|
|
|
32
32
|
|
|
33
33
|
def observe_checkbox(page: Any) -> None:
|
|
34
34
|
"""Observe readiness only; never read or write the verification response."""
|
|
35
|
-
from
|
|
35
|
+
from ...driver import main_world
|
|
36
36
|
|
|
37
37
|
page.evaluate(_OBSERVE_SCRIPT, **main_world(page)) # where the init script observes
|
|
38
38
|
|
|
@@ -45,8 +45,8 @@ def interaction_events(page: Any) -> list[dict[str, Any]]:
|
|
|
45
45
|
observed, or one that navigated away while it was read, reports nothing.
|
|
46
46
|
For diagnosis only — no caller may treat an event as proof of a pass.
|
|
47
47
|
"""
|
|
48
|
-
from
|
|
49
|
-
from
|
|
48
|
+
from ...driver import Error, main_world
|
|
49
|
+
from ...watchdog import CallAbandoned, call_limit
|
|
50
50
|
|
|
51
51
|
try:
|
|
52
52
|
with call_limit(READ_LIMIT_SEC):
|
|
@@ -108,12 +108,13 @@ _NAVIGATED = ("frame was detached", "frame has been detached", "element is not a
|
|
|
108
108
|
# can hang between two documents: one read waited 48 s and the article's page budget
|
|
109
109
|
# ran out before the page it led to opened (BMJ on Windows, 2026-11-11).
|
|
110
110
|
READ_LIMIT_SEC = 5
|
|
111
|
+
FRIENDLY_CAPTCHA = "Friendly Captcha"
|
|
111
112
|
|
|
112
113
|
|
|
113
114
|
def is_image_verification(page: Any) -> bool:
|
|
114
115
|
"""Image puzzles expose controls but may have no readable instructions."""
|
|
115
|
-
from
|
|
116
|
-
from
|
|
116
|
+
from ...driver import Error
|
|
117
|
+
from ...watchdog import CallAbandoned, call_limit
|
|
117
118
|
|
|
118
119
|
try:
|
|
119
120
|
with call_limit(READ_LIMIT_SEC):
|
|
@@ -158,8 +159,11 @@ _WIDGET_FRAMES: tuple[tuple[str, Callable[[str], bool]], ...] = (
|
|
|
158
159
|
("Tencent", re.compile(r"^https://(?:turing\.captcha\.qcloud\.com|t\.captcha\.qq\.com|"
|
|
159
160
|
r"ssl\.captcha\.qq\.com)/").search),
|
|
160
161
|
("Turnstile", lambda url: is_turnstile_frame(url)),
|
|
162
|
+
(FRIENDLY_CAPTCHA, lambda url: "frcapi.com/api/v2/captcha/widget" in url),
|
|
161
163
|
)
|
|
162
164
|
_WIDGET_ELEMENTS = (
|
|
165
|
+
("Turnstile", ".cf-turnstile[data-sitekey]"),
|
|
166
|
+
(FRIENDLY_CAPTCHA, ".frc-captcha"),
|
|
163
167
|
("GeeTest", ".geetest_holder, .geetest_panel, .geetest_box, .geetest_captcha"),
|
|
164
168
|
("Aliyun", "[id^='aliyunCaptcha-'], #nc_1_wrapper"),
|
|
165
169
|
("Tencent", "#tcaptcha_iframe, #tcaptcha_transform"),
|
|
@@ -167,11 +171,13 @@ _WIDGET_ELEMENTS = (
|
|
|
167
171
|
)
|
|
168
172
|
# Longer than this, the page is more than a verification interstitial.
|
|
169
173
|
_WIDGET_PAGE_TEXT = 2500
|
|
170
|
-
_WIDGET_PAGE_JS = r"""([groups, longest]) => {
|
|
174
|
+
_WIDGET_PAGE_JS = r"""([groups, longest, friendlyCaptcha]) => {
|
|
171
175
|
if (document.querySelector('meta[name="citation_doi"], meta[name="citation_title"]')) return '#page';
|
|
172
|
-
|
|
176
|
+
const text = (document.body?.innerText || '').trim();
|
|
177
|
+
if (text.length > longest) return '#page';
|
|
173
178
|
const shown = el => { const r = el.getBoundingClientRect(), s = getComputedStyle(el);
|
|
174
179
|
return r.width > 0 && r.height > 0 && s.visibility !== 'hidden' && s.display !== 'none'; };
|
|
180
|
+
if (/^verification required!?$/im.test(text) && /\bfriendly captcha\b/i.test(text)) return friendlyCaptcha;
|
|
175
181
|
for (const [name, selector] of groups)
|
|
176
182
|
if ([...document.querySelectorAll(selector)].some(shown)) return name;
|
|
177
183
|
if ([...document.scripts].some(s => /^https:\/\/[^/]*\.captcha\.awswaf\.com\//.test(s.src || ''))) return 'AWS WAF';
|
|
@@ -182,12 +188,12 @@ _WIDGET_PAGE_JS = r"""([groups, longest]) => {
|
|
|
182
188
|
def verification_widget(page: Any, *, manual_only: bool = False) -> str:
|
|
183
189
|
"""The provider of a visible verification widget making up ``page``, or "".
|
|
184
190
|
``manual_only``: leave out Turnstile, which the program may click itself."""
|
|
185
|
-
from
|
|
186
|
-
from
|
|
191
|
+
from ...driver import Error
|
|
192
|
+
from ...watchdog import CallAbandoned, call_limit
|
|
187
193
|
|
|
188
194
|
try:
|
|
189
195
|
with call_limit(READ_LIMIT_SEC):
|
|
190
|
-
found = page.evaluate(_WIDGET_PAGE_JS, [
|
|
196
|
+
found = page.evaluate(_WIDGET_PAGE_JS, [list(_WIDGET_ELEMENTS), _WIDGET_PAGE_TEXT, FRIENDLY_CAPTCHA])
|
|
191
197
|
except CallAbandoned:
|
|
192
198
|
return ""
|
|
193
199
|
except Error as exc:
|
|
@@ -197,6 +203,8 @@ def verification_widget(page: Any, *, manual_only: bool = False) -> str:
|
|
|
197
203
|
found = found if isinstance(found, str) else ""
|
|
198
204
|
if found == "#page":
|
|
199
205
|
return ""
|
|
206
|
+
if found == "Turnstile" and manual_only:
|
|
207
|
+
found = ""
|
|
200
208
|
if found:
|
|
201
209
|
return found
|
|
202
210
|
frames = getattr(page, "frames", ())
|
|
@@ -223,8 +231,8 @@ def verification_widget(page: Any, *, manual_only: bool = False) -> str:
|
|
|
223
231
|
|
|
224
232
|
def has_visible_recaptcha(page: Any) -> bool:
|
|
225
233
|
"""Detect a reCAPTCHA prompt that remains after the outer page changes."""
|
|
226
|
-
from
|
|
227
|
-
from
|
|
234
|
+
from ...driver import Error
|
|
235
|
+
from ...watchdog import CallAbandoned, call_limit
|
|
228
236
|
|
|
229
237
|
for frame in page.frames:
|
|
230
238
|
parsed = urlsplit(str(frame.url or ""))
|
|
@@ -273,7 +281,7 @@ def click_checkbox(page: Any, *, timeout_ms: int, checkpoint: Callable[[], None]
|
|
|
273
281
|
use its standard checkbox position. Expanded puzzles are left alone.
|
|
274
282
|
"""
|
|
275
283
|
from . import pointer
|
|
276
|
-
from
|
|
284
|
+
from ...driver import Error, TimeoutError, main_world
|
|
277
285
|
|
|
278
286
|
def note(reason: str) -> None:
|
|
279
287
|
if observation is not None:
|
|
@@ -392,3 +400,76 @@ def click_checkbox(page: Any, *, timeout_ms: int, checkpoint: Callable[[], None]
|
|
|
392
400
|
continue
|
|
393
401
|
raise
|
|
394
402
|
return "unavailable" if unavailable else "absent"
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
_CLOUDFLARE_FRAME = ("challenges.cloudflare.com", "/cdn-cgi/challenge-platform", "turnstile")
|
|
406
|
+
_RECAPTCHA_FRAME = ("/recaptcha/api2/", "/recaptcha/enterprise/")
|
|
407
|
+
_HCAPTCHA_FRAME = ("hcaptcha.com/captcha/",)
|
|
408
|
+
_AWS_FRAME = ("captcha.awswaf.com/",)
|
|
409
|
+
_CLOUDFLARE_TITLES = ("just a moment", "attention required", "verifying you are human",
|
|
410
|
+
"checking your browser", "verification required")
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
_AWS_WAF_SCRIPT = "/^https:\\/\\/[^/]*\\.captcha\\.awswaf\\.com\\//"
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
def _aws_waf_armed(page: Any) -> bool:
|
|
417
|
+
"""AWS WAF's own script on the outer page. Its button lives there, not in a
|
|
418
|
+
provider frame, so the iframe addresses above never show it; without this a
|
|
419
|
+
page carrying AWS WAF falls through to ``other``."""
|
|
420
|
+
from ...driver import Error
|
|
421
|
+
from ...watchdog import CallAbandoned, call_limit
|
|
422
|
+
|
|
423
|
+
js = ("() => [...document.scripts].some(s => "
|
|
424
|
+
+ _AWS_WAF_SCRIPT + ".test(s.src || ''))")
|
|
425
|
+
try:
|
|
426
|
+
with call_limit(READ_LIMIT_SEC):
|
|
427
|
+
return page.evaluate(js) is True
|
|
428
|
+
except CallAbandoned:
|
|
429
|
+
return False
|
|
430
|
+
except Error as exc:
|
|
431
|
+
if any(text in str(exc).lower() for text in _NAVIGATED):
|
|
432
|
+
return False # the page went on: the next check reads the new one
|
|
433
|
+
raise
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
def challenge_kind(page: Any) -> str:
|
|
437
|
+
"""Identify the provider for the verification handoff decision."""
|
|
438
|
+
|
|
439
|
+
from .. import detection
|
|
440
|
+
|
|
441
|
+
try:
|
|
442
|
+
url = str(getattr(page, "url", "") or "").lower()
|
|
443
|
+
except Exception: # noqa: BLE001
|
|
444
|
+
url = ""
|
|
445
|
+
try:
|
|
446
|
+
title = str(getattr(page, "title", lambda: "")() or "")
|
|
447
|
+
except Exception: # noqa: BLE001
|
|
448
|
+
title = ""
|
|
449
|
+
frames: list[str] = []
|
|
450
|
+
try:
|
|
451
|
+
frames = [str(getattr(frame, "url", "") or "").lower() for frame in page.frames]
|
|
452
|
+
except Exception: # noqa: BLE001
|
|
453
|
+
frames = []
|
|
454
|
+
joined = " ".join(frames)
|
|
455
|
+
|
|
456
|
+
if detection.looks_like_challenge(url, title):
|
|
457
|
+
return "cloudflare"
|
|
458
|
+
if any(is_turnstile_frame(frame) for frame in frames) or verification_widget(page) == "Turnstile":
|
|
459
|
+
return "turnstile"
|
|
460
|
+
if any(marker in joined for marker in _CLOUDFLARE_FRAME):
|
|
461
|
+
return "cloudflare"
|
|
462
|
+
if not detection.looks_like_challenge(url, title) and verification_widget(page) == FRIENDLY_CAPTCHA:
|
|
463
|
+
return "friendlycaptcha"
|
|
464
|
+
if any(marker in joined for marker in _RECAPTCHA_FRAME) or has_visible_recaptcha(page):
|
|
465
|
+
return "recaptcha"
|
|
466
|
+
if any(marker in joined for marker in _HCAPTCHA_FRAME):
|
|
467
|
+
return "hcaptcha"
|
|
468
|
+
if any(marker in joined for marker in _AWS_FRAME) or _aws_waf_armed(page):
|
|
469
|
+
return "awswaf"
|
|
470
|
+
lowered = title.lower()
|
|
471
|
+
if any(signal in lowered for signal in _CLOUDFLARE_TITLES):
|
|
472
|
+
return "cloudflare"
|
|
473
|
+
if detection.looks_like_challenge(url, title):
|
|
474
|
+
return "other" # 认得出是验证页、但不是 Cloudflare(AMS 的 Human Verification 就是这一类)
|
|
475
|
+
return "other" if (url or title) else "unknown"
|
|
@@ -103,7 +103,7 @@ def press(page: Any, rect: dict[str, Any], *, point: dict[str, float] | None = N
|
|
|
103
103
|
if not all(math.isfinite(value) for value in target):
|
|
104
104
|
return False
|
|
105
105
|
|
|
106
|
-
from
|
|
106
|
+
from ...driver import Error
|
|
107
107
|
|
|
108
108
|
try:
|
|
109
109
|
hit = page.evaluate("""([x, y]) => {
|
|
@@ -203,7 +203,7 @@ def approach(page: Any, rect: dict[str, Any], *, point: dict[str, float] | None
|
|
|
203
203
|
c2 = (start[0] + dx * random_source.uniform(0.60, 0.80) + normal[0] * bend * 0.4,
|
|
204
204
|
start[1] + dy * random_source.uniform(0.60, 0.80) + normal[1] * bend * 0.4)
|
|
205
205
|
|
|
206
|
-
from
|
|
206
|
+
from ...driver import Error # late: the module imports the driver's error classes
|
|
207
207
|
|
|
208
208
|
try:
|
|
209
209
|
move(start[0], start[1], steps=1)
|