papersearch 0.7.3 → 0.8.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/NOTICE +8 -37
- package/README.fr.md +265 -0
- package/README.ja.md +265 -0
- package/README.ko.md +265 -0
- package/README.md +149 -148
- package/README.zh-Hant.md +265 -0
- package/README.zh.md +265 -0
- package/dist/capabilities/download/batch/batch.d.ts +20 -1
- package/dist/capabilities/download/batch/batch.d.ts.map +1 -1
- package/dist/capabilities/download/batch/batch.js +1057 -208
- 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/batch/windowPlan.d.ts +96 -0
- package/dist/capabilities/download/batch/windowPlan.d.ts.map +1 -0
- package/dist/capabilities/download/batch/windowPlan.js +196 -0
- package/dist/capabilities/download/batch/windowPlan.js.map +1 -0
- 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 +46 -3
- 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/content/pdf/open/tiers/scihub.d.ts.map +1 -1
- package/dist/capabilities/download/content/pdf/open/tiers/scihub.js +3 -1
- package/dist/capabilities/download/content/pdf/open/tiers/scihub.js.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/http/hostGate.d.ts +24 -0
- package/dist/infrastructure/http/hostGate.d.ts.map +1 -0
- package/dist/infrastructure/http/hostGate.js +72 -0
- package/dist/infrastructure/http/hostGate.js.map +1 -0
- package/dist/infrastructure/pdf/PdfDownload.d.ts +1 -0
- package/dist/infrastructure/pdf/PdfDownload.d.ts.map +1 -1
- package/dist/infrastructure/pdf/PdfDownload.js +6 -1
- package/dist/infrastructure/pdf/PdfDownload.js.map +1 -1
- package/dist/infrastructure/runlog/RunLedger.d.ts +14 -0
- package/dist/infrastructure/runlog/RunLedger.d.ts.map +1 -1
- package/dist/infrastructure/runlog/RunLedger.js +30 -4
- 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 +13 -2
- package/dist/infrastructure/school/SchoolMcpClient.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolMcpClient.js +138 -15
- 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 +9 -0
- package/dist/infrastructure/school/SchoolReadiness.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolReadiness.js +10 -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 +73 -1
- package/dist/infrastructure/school/types.d.ts.map +1 -1
- package/dist/infrastructure/school/types.js.map +1 -1
- package/dist/infrastructure/security/SecurityUtils.d.ts.map +1 -1
- package/dist/infrastructure/security/SecurityUtils.js +6 -2
- package/dist/infrastructure/security/SecurityUtils.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 +68 -20
- package/dist/management/failures/index.js.map +1 -1
- package/dist/management/school/autoUpdate.d.ts.map +1 -1
- package/dist/management/school/autoUpdate.js +9 -1
- package/dist/management/school/autoUpdate.js.map +1 -1
- package/dist/management/school/cliProgress.d.ts.map +1 -1
- package/dist/management/school/cliProgress.js +3 -1
- package/dist/management/school/cliProgress.js.map +1 -1
- package/package.json +8 -3
- 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 +19 -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 +52 -13
- 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 +12 -3
- package/school/paper_search_school/adapters/platforms/figshare/__init__.py +23 -4
- 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 +526 -147
- package/school/paper_search_school/assets/capsule_en.json +140 -49
- package/school/paper_search_school/assets/capsule_fr.json +141 -50
- package/school/paper_search_school/assets/capsule_ja.json +140 -49
- package/school/paper_search_school/assets/capsule_ko.json +140 -49
- package/school/paper_search_school/assets/capsule_zh-Hant.json +134 -48
- package/school/paper_search_school/browser/backend.py +125 -4
- package/school/paper_search_school/browser/batch_session.py +189 -8
- package/school/paper_search_school/browser/challenge/__init__.py +12 -9
- package/school/paper_search_school/browser/challenge/continuation.py +83 -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 +128 -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/pro.py +24 -0
- package/school/paper_search_school/browser/challenge/services/__init__.py +1 -0
- package/school/paper_search_school/browser/challenge/services/solver.py +292 -0
- package/school/paper_search_school/browser/engine.py +4 -1
- package/school/paper_search_school/browser/user_turn.py +126 -0
- package/school/paper_search_school/browser/watchdog.py +213 -60
- package/school/paper_search_school/cli_config.py +10 -5
- package/school/paper_search_school/config.py +16 -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 +52 -18
- package/school/paper_search_school/engine/batch_access.py +62 -16
- package/school/paper_search_school/engine/batch_capture.py +260 -31
- 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 +52 -3
- package/school/paper_search_school/engine/batch_login.py +398 -36
- package/school/paper_search_school/engine/batch_pdf_urls.py +38 -7
- package/school/paper_search_school/engine/batch_user.py +48 -3
- package/school/paper_search_school/engine/batch_waits.py +221 -14
- package/school/paper_search_school/engine/bridge.py +29 -6
- package/school/paper_search_school/engine/fulltext_page.py +55 -8
- package/school/paper_search_school/engine/router.py +16 -1
- package/school/paper_search_school/engine/supplements.py +7 -1
- package/school/paper_search_school/entitlements.py +29 -1
- package/school/paper_search_school/pdf_utils.py +25 -16
- package/school/paper_search_school/progress_capsule.py +69 -11
- package/school/paper_search_school/progress_reporter.py +243 -11
- package/school/paper_search_school/progress_view.py +205 -91
- 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/rate_limit.py +24 -1
- package/school/paper_search_school/school_login.py +170 -8
- package/school/paper_search_school/school_test.py +1 -1
- package/school/paper_search_school/server.py +179 -23
- package/school/paper_search_school/user_settings.py +46 -4
- 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/README.en.md +0 -264
- package/school/paper_search_school/browser/challenge/prompt.py +0 -154
|
@@ -50,14 +50,23 @@ def _sent_as_attachment(headers: dict[str, str]) -> bool:
|
|
|
50
50
|
return headers.get("content-disposition", "").strip().lower().startswith("attachment")
|
|
51
51
|
|
|
52
52
|
|
|
53
|
+
# A PDF control's link that opens a new tab opens in this one, whose PDF responses are watched.
|
|
54
|
+
_SAME_TAB_JS = """el => { const a = el.closest('a[target]');
|
|
55
|
+
if (a && (a.getAttribute('target') || '').toLowerCase() === '_blank') a.setAttribute('target', '_self'); }"""
|
|
56
|
+
|
|
57
|
+
|
|
53
58
|
# A PDF larger than this is read in pieces (Fetch.takeResponseBodyAsStream), the step's time
|
|
54
59
|
# going on while pieces arrive: read whole in one call it was cut at the step's minute, and the
|
|
55
60
|
# page's own copy then fetched in its place took the tab down (Cell, 108 MB, 2026-11-18).
|
|
56
61
|
# A PDF over this, or one whose size is not given, is read in pieces, the PDF step's time going on
|
|
57
62
|
# while they arrive: IEEE's getPDF.jsp sent a 31.8 MB PDF and a 37 MB one without a size, read in one
|
|
58
63
|
# call in 46 and 57 s of the step's 60 (2026-11-18; 32 MB before).
|
|
59
|
-
|
|
60
|
-
|
|
64
|
+
# Over 2 MB since 2026-11-26 (8 before), in pieces of 256 KB (4 MB before): Optica's 4 MB pieces came in 41 and 44 s
|
|
65
|
+
# at about 100 KB/s and the third went past STREAM_STALL_SEC (two reviews of tens of MB lost after five minutes); a
|
|
66
|
+
# small piece comes back every few seconds on a slow line, so only a real stop ends the read, and the window shows
|
|
67
|
+
# the file's size and how far it has come (progress_reporter.Transfer).
|
|
68
|
+
STREAM_PDF_BYTES = 2 * 1024 * 1024
|
|
69
|
+
STREAM_PIECE_BYTES = 256 * 1024
|
|
61
70
|
# How long a piece may take before the read counts as stalled.
|
|
62
71
|
STREAM_STALL_SEC = 45
|
|
63
72
|
|
|
@@ -95,6 +104,18 @@ class CaptureMixin:
|
|
|
95
104
|
captured["login_wall"] = True
|
|
96
105
|
return True
|
|
97
106
|
|
|
107
|
+
def _paywall_answered_before_login(self, result: DownloadResult) -> bool:
|
|
108
|
+
"""This capture, the PDF tried first before the school's login (access not known, ``_pdf_first``), had a PDF
|
|
109
|
+
address answer 403/429 with the article's own page (``pdf_step_article_page``): the site's other addresses
|
|
110
|
+
answer the same until the login, which comes next, then every address is tried again. Wiley's Angewandte
|
|
111
|
+
(10.1002/anie.202516998, Windows 2026-11-24): epdf, pdfdirect and pdf each answered its paywall page in about
|
|
112
|
+
20 s and the PDF step's page budget ran out before the login, 原因不明 · 页面处理超时; the next paper of the
|
|
113
|
+
journal went through the login and was saved."""
|
|
114
|
+
if not getattr(result, "_pdf_first", False) or self._school_login_done():
|
|
115
|
+
return False
|
|
116
|
+
started = max((i for i, e in enumerate(result.events) if e.get("state") == "pdf_capture_started"), default=-1)
|
|
117
|
+
return any(e.get("state") == "pdf_step_article_page" for e in result.events[started + 1:])
|
|
118
|
+
|
|
98
119
|
def _probe_pdf_while_waiting(self, page: Any, result: DownloadResult, *, after_login: bool) -> bool:
|
|
99
120
|
"""While the login waits: this article's PDF from an open tab or fetched
|
|
100
121
|
with the browser's session (``_probe_pdf``); found, the item ends with it
|
|
@@ -120,32 +141,57 @@ class CaptureMixin:
|
|
|
120
141
|
# PDF attempts that came back as a web page (``_record_pdf_attempt``).
|
|
121
142
|
_WEB_PAGE_OUTCOMES = frozenset({"html page", "paywall"})
|
|
122
143
|
|
|
123
|
-
def
|
|
124
|
-
"""
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
144
|
+
def _pdf_sent_to_article(self, page: Any, result: DownloadResult, since: int) -> list[dict[str, Any]]:
|
|
145
|
+
"""The PDF attempts from ``since`` on that were sent to the article's own web page:
|
|
146
|
+
redirected there, or the PDF address showing that page (the adapter's
|
|
147
|
+
``pdf_address_shows_article_page``, or its 403/429 answer printing the article's
|
|
148
|
+
title, ``pdf_step_article_page``). [] unless every attempt came back as a web page
|
|
149
|
+
or nothing, and the tab is on no login or verification page. JAMA's ``/articlepdf/``
|
|
150
|
+
answered with ``/fullarticle/`` (10.1001/jama.2025.19316), jacc.org's ``/doi/pdf/``
|
|
151
|
+
with the article's page and a 403 (10.1016/j.jcmg.2025.09.021; Windows 2026-11-23)."""
|
|
129
152
|
def plain(url: Any) -> str:
|
|
130
153
|
parsed = urlparse(str(url or ""))
|
|
131
154
|
return f"{parsed.hostname}{parsed.path}".lower().rstrip("/")
|
|
132
155
|
|
|
156
|
+
answered = {plain(str(e.get("detail") or "").split(" | ", 1)[0].split(" ", 1)[-1])
|
|
157
|
+
for e in result.events if e.get("state") == "pdf_step_article_page"}
|
|
133
158
|
attempts = result.pdf_attempts[since:]
|
|
134
159
|
sent_back = [a for a in attempts if a.get("outcome") in self._WEB_PAGE_OUTCOMES
|
|
135
|
-
and (plain(a.get("final_url")) != plain(a.get("url")) or self.adapter.pdf_address_shows_article_page
|
|
160
|
+
and (plain(a.get("final_url")) != plain(a.get("url")) or self.adapter.pdf_address_shows_article_page
|
|
161
|
+
or plain(a.get("final_url")) in answered)
|
|
136
162
|
and self._is_success_article_url(str(a.get("final_url") or ""))]
|
|
137
163
|
url = str(getattr(page, "url", "") or "")
|
|
138
|
-
if (not sent_back
|
|
164
|
+
if (not sent_back
|
|
139
165
|
or any(a.get("outcome") not in self._WEB_PAGE_OUTCOMES | {"no pdf"} for a in attempts)
|
|
140
166
|
or self._is_auth_page(url) or self._is_challenge_page(page)):
|
|
167
|
+
return []
|
|
168
|
+
return sent_back
|
|
169
|
+
|
|
170
|
+
def _pdf_sent_to_article_after_login(self, page: Any, result: DownloadResult, since: int) -> bool:
|
|
171
|
+
"""After this item's school login, or with the school's session shown on the
|
|
172
|
+
page (signed in by an earlier item), the PDF attempts from ``since`` on were
|
|
173
|
+
sent to the article's own web page (``_pdf_sent_to_article``). Missing
|
|
174
|
+
entitlement additionally requires the page's denial, purchase offer or
|
|
175
|
+
abstract-only evidence. A redirect alone can also happen on a freely
|
|
176
|
+
readable article and does not prove missing access.
|
|
177
|
+
NEJM Catalyst (10.1056/cat.24.0478, Windows 2026-11-23): "Welcome: <school>"
|
|
178
|
+
in the header, "Get Access" over the abstract, the PDF address answering
|
|
179
|
+
with that page; it ended as pdf_not_captured, the school never switched."""
|
|
180
|
+
sent_back = self._pdf_sent_to_article(page, result, since)
|
|
181
|
+
if not sent_back:
|
|
141
182
|
return False
|
|
142
|
-
|
|
183
|
+
signed_in = self._school_login_done()
|
|
184
|
+
session = not signed_in and self._institution_session(page) == "ours"
|
|
185
|
+
if not (signed_in or session):
|
|
186
|
+
return False
|
|
187
|
+
evidence = self._no_access_after_login(page, result, session_shown=session)
|
|
143
188
|
if not evidence:
|
|
144
189
|
return False
|
|
145
190
|
last = sent_back[-1]
|
|
146
191
|
result.reason = "institution_pdf_entitlement_missing"
|
|
147
192
|
self._event(result, "no_access_after_login",
|
|
148
|
-
f"PDF
|
|
193
|
+
f"PDF {'with the school signed in' if session else 'after the school login'} sent to the "
|
|
194
|
+
f"article's web page: {str(last.get('url'))[:120]} -> "
|
|
149
195
|
f"{str(last.get('final_url'))[:160]} | {evidence[:160]}")
|
|
150
196
|
self._snapshot(page, result, "not subscribed")
|
|
151
197
|
return True
|
|
@@ -304,6 +350,88 @@ class CaptureMixin:
|
|
|
304
350
|
f"after {time.time() - started:.1f} s at {str(getattr(page, 'url', ''))[:160]}")
|
|
305
351
|
return True
|
|
306
352
|
|
|
353
|
+
# Anything on the page naming a PDF: a citation PDF address, a link's or control's address,
|
|
354
|
+
# title or label, the page's text.
|
|
355
|
+
_NAMES_A_PDF_JS = """() => !!document.querySelector('meta[name$="pdf_url" i]')
|
|
356
|
+
|| [...document.querySelectorAll('a, button, [role="button"]')].some(el => /pdf/i.test(
|
|
357
|
+
[el.getAttribute('href'), el.getAttribute('title'), el.getAttribute('aria-label')].join(' ')))
|
|
358
|
+
|| /pdf/i.test(document.body ? document.body.innerText || '' : '')"""
|
|
359
|
+
|
|
360
|
+
def _page_offers_no_pdf(self, page: Any) -> bool:
|
|
361
|
+
"""Nothing on the article's page names a PDF (``_NAMES_A_PDF_JS``): the site gives this
|
|
362
|
+
article as a web page only. CAA Reviews' open reviews have no PDF at all, and were reported
|
|
363
|
+
as "PDF not captured" with no reason (2026-11-24). A page that names one and gave none
|
|
364
|
+
is not this."""
|
|
365
|
+
try:
|
|
366
|
+
return page.evaluate(self._NAMES_A_PDF_JS) is False
|
|
367
|
+
except Exception as exc:
|
|
368
|
+
if not _is_browser_error(exc):
|
|
369
|
+
raise
|
|
370
|
+
return False
|
|
371
|
+
|
|
372
|
+
# A box the reader ticks to agree to the site's terms before its download links work, on the
|
|
373
|
+
# article's own page. ufn.ru (Physics-Uspekhi, 2026-11-25): "By downloading this file I agree
|
|
374
|
+
# with the terms of use" beside an unticked box; until it is ticked the site's script takes the
|
|
375
|
+
# PDF link's address away and greys it (ufn.js: copyright-agree, data-ehref), and the click on it
|
|
376
|
+
# gave nothing. The user asked for such boxes to be ticked for them, in the shared rules
|
|
377
|
+
# (2026-11-25), as the publisher's terms form on the way to the school is accepted (2026-11-08).
|
|
378
|
+
# Its words (its labels, else the nearest enclosing text up to 4 levels, at most 600 characters)
|
|
379
|
+
# agree to terms, conditions, a licence or copyright and speak of the download, the PDF or the
|
|
380
|
+
# full text, or the page has a download control held back (disabled, greyed, a link with no
|
|
381
|
+
# address). Never a box in a form with a password, nor one about newsletters, offers, cookies,
|
|
382
|
+
# privacy, staying signed in or an account.
|
|
383
|
+
_DOWNLOAD_TERMS_JS = r"""() => {
|
|
384
|
+
const shown = el => !!el && el.getClientRects().length > 0 && getComputedStyle(el).visibility !== 'hidden';
|
|
385
|
+
const words = el => (el.innerText || el.textContent || '').replace(/\s+/g, ' ').trim();
|
|
386
|
+
const AGREE = /\b(?:agree|accept)\b|同意|接受/i;
|
|
387
|
+
const TERMS = /\bterms\b|\bconditions\b|copyright|\blicen[cs]e\b|条款|协议|版权|许可/i;
|
|
388
|
+
const DOWNLOAD = /download|\bpdf\b|full[ -]?text|下载|全文/i;
|
|
389
|
+
const NOT = /newsletter|subscri|marketing|promot|\boffers?\b|cookie|privacy|remember me|keep me|signed in|sign ?up|regist|account|password|订阅|营销|推广|隐私|记住|注册|账号|账户|密码/i;
|
|
390
|
+
const held = [...document.querySelectorAll('a, button, [role="button"]')].some(el => shown(el)
|
|
391
|
+
&& DOWNLOAD.test(`${words(el)} ${el.getAttribute('class') || ''} ${el.getAttribute('aria-label') || ''}`)
|
|
392
|
+
&& (el.disabled || el.getAttribute('aria-disabled') === 'true' || /\bdisabled\b/i.test(el.getAttribute('class') || '')
|
|
393
|
+
|| (el.tagName === 'A' && !el.hasAttribute('href'))));
|
|
394
|
+
for (const box of document.querySelectorAll('input[type="checkbox"]')) {
|
|
395
|
+
if (box.checked || box.disabled) continue;
|
|
396
|
+
const labels = [...(box.labels || [])].filter(shown);
|
|
397
|
+
if (!shown(box) && !labels.length) continue;
|
|
398
|
+
const form = box.closest('form');
|
|
399
|
+
if (form && form.querySelector('input[type="password"]')) continue;
|
|
400
|
+
let text = labels.map(words).join(' ');
|
|
401
|
+
for (let el = box.parentElement, up = 0; el && up < 4 && !text; el = el.parentElement, up++) text = words(el);
|
|
402
|
+
if (!text || text.length > 600 || !AGREE.test(text) || !TERMS.test(text) || NOT.test(text)) continue;
|
|
403
|
+
if (!DOWNLOAD.test(text) && !held) continue;
|
|
404
|
+
document.querySelectorAll('[data-papersearch-download-terms]')
|
|
405
|
+
.forEach(el => el.removeAttribute('data-papersearch-download-terms'));
|
|
406
|
+
(shown(box) ? box : labels[0]).setAttribute('data-papersearch-download-terms', '1');
|
|
407
|
+
return text.slice(0, 200);
|
|
408
|
+
}
|
|
409
|
+
return '';
|
|
410
|
+
}"""
|
|
411
|
+
|
|
412
|
+
def _agree_to_download_terms(self, page: Any, result: DownloadResult) -> bool:
|
|
413
|
+
"""Tick the site's box agreeing to its terms that holds back its download links
|
|
414
|
+
(``_DOWNLOAD_TERMS_JS``), on the article's own page, never a school's or a federation's;
|
|
415
|
+
True when ticked. The links are read after it, once the site's script has given them their
|
|
416
|
+
addresses."""
|
|
417
|
+
url = str(getattr(page, "url", "") or "")
|
|
418
|
+
if (not url.startswith("http") or self._is_idp_host(urlparse(url).netloc)
|
|
419
|
+
or self._school_or_federation_page(url.split("#", 1)[0], result, include_publisher_chooser=False)):
|
|
420
|
+
return False
|
|
421
|
+
try:
|
|
422
|
+
terms = page.evaluate(self._DOWNLOAD_TERMS_JS)
|
|
423
|
+
except Exception as exc:
|
|
424
|
+
if not _is_browser_error(exc):
|
|
425
|
+
raise
|
|
426
|
+
return False
|
|
427
|
+
if not terms or not isinstance(terms, str) or not self._click_control(
|
|
428
|
+
page, page.locator('[data-papersearch-download-terms="1"]').first, result, "agree to the download terms",
|
|
429
|
+
timeout_ms=3_000):
|
|
430
|
+
return False
|
|
431
|
+
self._event(result, "download_terms_agreed", f"{terms[:160]} @ {url[:160]}")
|
|
432
|
+
settle(page, 1_000)
|
|
433
|
+
return True
|
|
434
|
+
|
|
307
435
|
def _nothing_tried_evidence(self, page: Any, doi: str) -> str:
|
|
308
436
|
"""The page and its access verdict, and the PDF addresses it offered."""
|
|
309
437
|
try:
|
|
@@ -379,21 +507,24 @@ class CaptureMixin:
|
|
|
379
507
|
except Exception:
|
|
380
508
|
pass
|
|
381
509
|
|
|
382
|
-
# Figshare links: their files are found by its own API in the attachment step.
|
|
383
|
-
_FIGSHARE_LINKED_JS = "() => !!document.querySelector('a[href*=\"figshare.com\"]')"
|
|
384
|
-
|
|
385
510
|
def _remember_listed_supplements(self, page: Any, doi: str, result: DownloadResult) -> None:
|
|
386
511
|
"""The files the article page lists, read before the PDF takes its tab: the
|
|
387
512
|
attachment step then need not load the page again (AHA's page took more
|
|
388
513
|
than that step's 60 s once, 2026-11-08). Only from an adapter that reads
|
|
389
|
-
them without leaving the page
|
|
514
|
+
them without leaving the page (its ``listed_supplement_links``: the files, [] when
|
|
515
|
+
the page lists none, None when it cannot say), and not beside Figshare
|
|
516
|
+
resources, whose files Figshare's API gives in the attachment step (Optica's are
|
|
517
|
+
linked as doi.org/10.6084/m9.figshare.<id>, 2026-11-26)."""
|
|
390
518
|
read = getattr(self.adapter, "listed_supplement_links", None)
|
|
391
|
-
if read is None or getattr(result, "_listed_supplements", None):
|
|
519
|
+
if read is None or getattr(result, "_listed_supplements", None) is not None:
|
|
392
520
|
return
|
|
393
521
|
try:
|
|
394
522
|
links = read(page, doi)
|
|
395
|
-
if links
|
|
396
|
-
|
|
523
|
+
if links is not None:
|
|
524
|
+
from ..adapters.platforms.figshare import resources_linked
|
|
525
|
+
|
|
526
|
+
if not resources_linked(page):
|
|
527
|
+
result._listed_supplements = list(links)
|
|
397
528
|
except Exception as exc:
|
|
398
529
|
if not _is_browser_error(exc):
|
|
399
530
|
raise
|
|
@@ -409,25 +540,38 @@ class CaptureMixin:
|
|
|
409
540
|
fetched after the PDF, in the bridge, with the browser's session, or with the session
|
|
410
541
|
kept here once the browser can no longer be asked then (``_fulltext_session``).
|
|
411
542
|
``target``: an address to read in a tab of its own instead (the article page again,
|
|
412
|
-
once the school's login came later).
|
|
543
|
+
once the school's login came later). The address the adapter names for the full text
|
|
544
|
+
is opened only when the page the browser is on does not show it already."""
|
|
413
545
|
if not self.config.get("fulltext") or getattr(result, "_fulltext_read", None):
|
|
414
546
|
return
|
|
415
547
|
|
|
416
|
-
|
|
548
|
+
named = self.adapter.fulltext_page_url(doi, str(getattr(page, "url", "") or ""))
|
|
549
|
+
target = named or target
|
|
417
550
|
tab = None
|
|
418
551
|
# The window says the Markdown's page is being read, then goes back to the part it was on.
|
|
419
552
|
before = progress_reporter.current_part()
|
|
420
553
|
progress_reporter.update(part="markdown", page_reading=True)
|
|
421
554
|
try:
|
|
422
555
|
with watchdog.operation(self.FULLTEXT_READ_SEC, "fulltext_page"):
|
|
556
|
+
if named and self._fulltext_shown_here(page):
|
|
557
|
+
# The article page shows its full text already: read here, not at the other
|
|
558
|
+
# address, which may serve less (MDPI, 2026-11-22: for 6 of 80 articles the
|
|
559
|
+
# article page was a full one by its size, the address with a query the abstract alone).
|
|
560
|
+
target = ""
|
|
561
|
+
gone = None
|
|
423
562
|
if target:
|
|
424
563
|
# The full text is another page than the article's (Thieme): a tab of its own.
|
|
425
564
|
from .batch_common import open_page
|
|
426
565
|
|
|
427
566
|
tab = page.context.new_page()
|
|
428
|
-
open_page(tab, target, timeout_ms=30_000)
|
|
429
|
-
|
|
430
|
-
|
|
567
|
+
gone = self._page_not_found(open_page(tab, target, timeout_ms=30_000))
|
|
568
|
+
if gone:
|
|
569
|
+
# No such page: the article has no full text there (J-STAGE's articles with their
|
|
570
|
+
# PDF alone, whose full-text address is a 404), not a page to wait 15 s on.
|
|
571
|
+
read, why = None, f"fulltext_not_shown: {urlparse(target).hostname or ''} answered {gone}"
|
|
572
|
+
else:
|
|
573
|
+
read, why = self._read_fulltext_page(tab or page, doi, result)
|
|
574
|
+
if read is None and not gone and why.startswith("fulltext_not_shown") and not self._pdf_only(why):
|
|
431
575
|
# No full text on the page: a paywall or a denial there is no access, not a
|
|
432
576
|
# page without its text (pnas.org's "Get full access to this article",
|
|
433
577
|
# said 文章页没有正文, 2026-11-17). The shared rules, as the access check reads them.
|
|
@@ -459,6 +603,19 @@ class CaptureMixin:
|
|
|
459
603
|
self._event(result, "fulltext_page_read",
|
|
460
604
|
f"{len(read['html'])} chars, {len(read['image_urls'])} images{prepared}{general}")
|
|
461
605
|
|
|
606
|
+
def _fulltext_shown_here(self, page: Any) -> bool:
|
|
607
|
+
"""Whether the page shows the full text now, by the adapter's own rule: one look, no
|
|
608
|
+
wait; False when the browser cannot say."""
|
|
609
|
+
shown_js = getattr(self.adapter, "fulltext_shown_js", None)
|
|
610
|
+
if not shown_js:
|
|
611
|
+
return False
|
|
612
|
+
try:
|
|
613
|
+
return page.evaluate(shown_js) is True
|
|
614
|
+
except Exception as exc:
|
|
615
|
+
if not _is_browser_error(exc):
|
|
616
|
+
raise
|
|
617
|
+
return False
|
|
618
|
+
|
|
462
619
|
# The longest wait for the page to load again before the second read.
|
|
463
620
|
FULLTEXT_REREAD_SETTLE_MS = 5_000
|
|
464
621
|
|
|
@@ -511,6 +668,13 @@ class CaptureMixin:
|
|
|
511
668
|
raise
|
|
512
669
|
return ""
|
|
513
670
|
|
|
671
|
+
@staticmethod
|
|
672
|
+
def _page_not_found(response: Any) -> int | None:
|
|
673
|
+
"""The status of a page that does not exist (404, 410), from its navigation's response;
|
|
674
|
+
None for any other, or when there is no response to ask."""
|
|
675
|
+
status = getattr(response, "status", None)
|
|
676
|
+
return status if isinstance(status, int) and status in (404, 410) else None
|
|
677
|
+
|
|
514
678
|
@staticmethod
|
|
515
679
|
def _pdf_only(why: str) -> bool:
|
|
516
680
|
"""The page is the PDF, or sends the reader to it for the text (``fulltext_page.PDF_ONLY``)."""
|
|
@@ -565,15 +729,16 @@ class CaptureMixin:
|
|
|
565
729
|
self._remember_fulltext_page(page, doi, result, target=str(result.final_url or self._article_url(doi)))
|
|
566
730
|
|
|
567
731
|
def _read_paused_pdf(self, cdp_session: Any, request_id: str, result: DownloadResult,
|
|
568
|
-
captured: dict[str, Any]) -> bytes:
|
|
732
|
+
captured: dict[str, Any], size: int = 0) -> bytes:
|
|
569
733
|
"""A large paused PDF response, read in pieces: while they arrive, the PDF step's time
|
|
570
|
-
goes on (``watchdog.extend_operation``); a piece that takes STREAM_STALL_SEC ends it.
|
|
734
|
+
goes on (``watchdog.extend_operation``); a piece that takes STREAM_STALL_SEC ends it.
|
|
735
|
+
``size``: its stated length, shown with what has come on the window's card."""
|
|
571
736
|
captured["receiving"] = True
|
|
572
737
|
handle = ""
|
|
573
738
|
pieces: list[bytes] = []
|
|
574
739
|
started = time.monotonic()
|
|
575
740
|
try:
|
|
576
|
-
with transfer(result):
|
|
741
|
+
with transfer(result), progress_reporter.Transfer("pdf", size) as arriving:
|
|
577
742
|
handle = cdp_session.send("Fetch.takeResponseBodyAsStream", {"requestId": request_id})["stream"]
|
|
578
743
|
while True:
|
|
579
744
|
watchdog.extend_operation(STREAM_STALL_SEC)
|
|
@@ -582,6 +747,7 @@ class CaptureMixin:
|
|
|
582
747
|
if data:
|
|
583
748
|
# CDP's plain stream chunks are UTF-8 text, not Latin-1 bytes.
|
|
584
749
|
pieces.append(base64.b64decode(data) if piece.get("base64Encoded") else data.encode("utf-8"))
|
|
750
|
+
arriving.add(len(pieces[-1]))
|
|
585
751
|
if piece.get("eof"):
|
|
586
752
|
break
|
|
587
753
|
body = b"".join(pieces)
|
|
@@ -602,7 +768,9 @@ class CaptureMixin:
|
|
|
602
768
|
``"ip_blocked"`` if a publisher IP-block signal (403/429 or block page)
|
|
603
769
|
was observed during capture, else ``None``.
|
|
604
770
|
"""
|
|
771
|
+
|
|
605
772
|
self._event(result, "pdf_capture_started")
|
|
773
|
+
self._agree_to_download_terms(page, result)
|
|
606
774
|
self._remember_listed_supplements(page, doi, result)
|
|
607
775
|
captured: dict[str, Any] = {"bytes": None, "url": "", "deferred_url": "", "block_reason": None, "receiving": False,
|
|
608
776
|
"suspect_block": None, "closed": False, "readers": set()}
|
|
@@ -754,7 +922,7 @@ class CaptureMixin:
|
|
|
754
922
|
size = _content_length(headers)
|
|
755
923
|
if not size or size > STREAM_PDF_BYTES:
|
|
756
924
|
try:
|
|
757
|
-
body = self._read_paused_pdf(cdp_session, request_id, result, captured)
|
|
925
|
+
body = self._read_paused_pdf(cdp_session, request_id, result, captured, size)
|
|
758
926
|
finally:
|
|
759
927
|
# Its body taken, the request cannot go on as it was: answered empty,
|
|
760
928
|
# the tab stays on the article page (as for an attachment below).
|
|
@@ -1043,7 +1211,21 @@ class CaptureMixin:
|
|
|
1043
1211
|
if not captured["bytes"] and self._pdf_step_hit_wall(page, result):
|
|
1044
1212
|
return None, "", None
|
|
1045
1213
|
if not captured["bytes"]:
|
|
1046
|
-
if self.
|
|
1214
|
+
if self._is_challenge_page(page) or self._challenge_shell(page):
|
|
1215
|
+
# The PDF link itself opened a verification page: the same
|
|
1216
|
+
# wait as anywhere else. It gets nothing? Then stop the
|
|
1217
|
+
# capture as at a login wall, so the article's school
|
|
1218
|
+
# login runs and the PDF is asked for again with the
|
|
1219
|
+
# session, instead of waiting on the user here (the PDF
|
|
1220
|
+
# address itself answers empty to Bright Data, 2026-11-25).
|
|
1221
|
+
if not self._wait_for_challenge(page, result, hand_over_only=True):
|
|
1222
|
+
if captured is not None:
|
|
1223
|
+
captured["login_wall"] = True
|
|
1224
|
+
return None, "", None
|
|
1225
|
+
if not captured["bytes"]:
|
|
1226
|
+
return None, "", captured["block_reason"]
|
|
1227
|
+
if (not captured["bytes"] and self._uses_article_pdf_validation()
|
|
1228
|
+
and not self._wait_for_challenge(page, result)):
|
|
1047
1229
|
return None, "", captured["block_reason"]
|
|
1048
1230
|
if entitlement_denied():
|
|
1049
1231
|
return None, "", None
|
|
@@ -1083,6 +1265,12 @@ class CaptureMixin:
|
|
|
1083
1265
|
continue
|
|
1084
1266
|
if entitlement_denied():
|
|
1085
1267
|
return None, "", None
|
|
1268
|
+
if self._paywall_answered_before_login(result):
|
|
1269
|
+
# The school's login first, then every address again (_paywall_answered_before_login).
|
|
1270
|
+
self._event(result, "pdf_candidates_after_login",
|
|
1271
|
+
f"{len(candidates) - candidates.index(pdf_url)} left: a PDF address answered with the "
|
|
1272
|
+
f"article's own page; the school's login first")
|
|
1273
|
+
return None, "", None
|
|
1086
1274
|
self._raise_on_publisher_content_error(page)
|
|
1087
1275
|
self._event(result, "pdf_candidate", pdf_url)
|
|
1088
1276
|
begin("url", pdf_url, time.time())
|
|
@@ -1095,6 +1283,11 @@ class CaptureMixin:
|
|
|
1095
1283
|
if captured.get("login_wall"):
|
|
1096
1284
|
return None, "", None
|
|
1097
1285
|
if self._is_challenge_page(page):
|
|
1286
|
+
# The same wait as everywhere else; nothing came? The
|
|
1287
|
+
# article's school login runs and the PDF is asked for
|
|
1288
|
+
# again with the session.
|
|
1289
|
+
if not self._wait_for_challenge(page, result, hand_over_only=True):
|
|
1290
|
+
captured["login_wall"] = True
|
|
1098
1291
|
return None, final_url, captured["block_reason"]
|
|
1099
1292
|
continue
|
|
1100
1293
|
try:
|
|
@@ -1272,6 +1465,8 @@ class CaptureMixin:
|
|
|
1272
1465
|
self._note_download_limit(page, result)
|
|
1273
1466
|
if outcome != "pdf ok" and not any(s["why"] == "pdf attempt failed" for s in result.snapshots):
|
|
1274
1467
|
self._snapshot(page, result, "pdf attempt failed")
|
|
1468
|
+
if outcome != "pdf ok":
|
|
1469
|
+
self._note_blocked_page(page, result, captured)
|
|
1275
1470
|
except Exception as exc: # the record never ends the capture
|
|
1276
1471
|
self._event(result, "pdf_attempt_record_error", f"{type(exc).__name__}: {str(exc)[:160]}")
|
|
1277
1472
|
|
|
@@ -1285,6 +1480,27 @@ class CaptureMixin:
|
|
|
1285
1480
|
r"download limit|(?:exceeded|reached)\b.{0,60}\bdownloads?\b|too many (?:pdf )?downloads"
|
|
1286
1481
|
r"|下载.{0,8}(?:达到|超过|超出).{0,4}(?:上限|限额|限制)", re.I | re.S)
|
|
1287
1482
|
|
|
1483
|
+
def _note_blocked_page(self, page: Any, result: DownloadResult, captured: dict[str, Any]) -> None:
|
|
1484
|
+
"""A PDF attempt that ended on the site's own page blocking or throttling this address
|
|
1485
|
+
(``_ip_blocked_words``; Optica, 2026-11-26: twelve articles in a row each tried the
|
|
1486
|
+
page's other PDF addresses, all answering the same, until the step's minute ran out, and
|
|
1487
|
+
ended as 页面或浏览器卡住): the step ends as blocked, its other addresses not asked for,
|
|
1488
|
+
and the batch waits on the site (three in a row) instead of going on into it."""
|
|
1489
|
+
if captured.get("bytes") or captured.get("block_reason"):
|
|
1490
|
+
return
|
|
1491
|
+
from ..browser import watchdog
|
|
1492
|
+
try:
|
|
1493
|
+
words = self._ip_blocked_words(self._body_text(page, 20_000))
|
|
1494
|
+
except Exception as exc:
|
|
1495
|
+
if exc is watchdog.interrupted:
|
|
1496
|
+
raise # the window's skip or stop
|
|
1497
|
+
return # a look for the record: the attempt is recorded either way
|
|
1498
|
+
if not words:
|
|
1499
|
+
return
|
|
1500
|
+
captured["block_reason"] = "ip_blocked"
|
|
1501
|
+
host = urlparse(str(getattr(page, "url", "") or "")).hostname or ""
|
|
1502
|
+
self._event(result, "ip_blocked_page", f'{host}: "{words[:200]}"')
|
|
1503
|
+
|
|
1288
1504
|
def _note_download_limit(self, page: Any, result: DownloadResult) -> None:
|
|
1289
1505
|
"""A PDF attempt that got no PDF, with a dialog over the page saying the downloads
|
|
1290
1506
|
are used up (ScienceDirect's "You have reached the daily bulk download limit" after
|
|
@@ -1396,12 +1612,14 @@ class CaptureMixin:
|
|
|
1396
1612
|
page, result, lambda href: self._article_pdf_link(href, keys, str(getattr(page, "url", "") or "")),
|
|
1397
1613
|
"current-doi-pdf-link", drop_download=self.adapter.keeps_pdf_out_of_downloads):
|
|
1398
1614
|
return True
|
|
1615
|
+
# A title or label naming PDF only on a control: Bioethics Open Research's "XML & PDF
|
|
1616
|
+
# downloads (all versions)" is the title of a counter in a list, clicked as the PDF (2026-11-24).
|
|
1399
1617
|
selectors = (
|
|
1400
1618
|
"a.xpl-btn-pdf",
|
|
1401
1619
|
".xpl-btn-pdf",
|
|
1402
1620
|
"a.stats-document-lh-action-downloadPdf_3",
|
|
1403
|
-
"[title*='PDF']",
|
|
1404
|
-
"[aria-label*='PDF']",
|
|
1621
|
+
"a[title*='PDF'], button[title*='PDF'], [role='button'][title*='PDF']",
|
|
1622
|
+
"a[aria-label*='PDF'], button[aria-label*='PDF'], [role='button'][aria-label*='PDF']",
|
|
1405
1623
|
"button:has-text('PDF')",
|
|
1406
1624
|
"a:has-text('PDF')",
|
|
1407
1625
|
)
|
|
@@ -1428,6 +1646,14 @@ class CaptureMixin:
|
|
|
1428
1646
|
or re.search(r"\b(?:supplement(?:ary|al)?|supporting information|disclosure form)\b", text, re.I)):
|
|
1429
1647
|
continue
|
|
1430
1648
|
detail = {"selector": selector, "text": text[:200], "href": href[:300]}
|
|
1649
|
+
# In the tab whose PDF responses are watched, as ScienceDirect's: a
|
|
1650
|
+
# target=_blank link's PDF in a tab of its own is lost (IJOR's
|
|
1651
|
+
# Squarespace "PDF" button, 2026-11-25).
|
|
1652
|
+
try:
|
|
1653
|
+
control.evaluate(_SAME_TAB_JS, timeout=2_000)
|
|
1654
|
+
except Exception as exc:
|
|
1655
|
+
if not _is_browser_error(exc):
|
|
1656
|
+
raise
|
|
1431
1657
|
if not self._click_control(page, control, result, f"pdf control: {selector}"):
|
|
1432
1658
|
continue # nothing was clicked (script_click_failed)
|
|
1433
1659
|
self._event(result, "pdf_button_clicked", json.dumps(detail, ensure_ascii=False))
|
|
@@ -1491,6 +1717,9 @@ class CaptureMixin:
|
|
|
1491
1717
|
text: textOf(target).slice(0, 200),
|
|
1492
1718
|
href: ((target.href || target.getAttribute('href') || target.getAttribute('formaction') || '') + '').slice(0, 300)
|
|
1493
1719
|
};
|
|
1720
|
+
// In this tab, whose PDF responses are watched (_SAME_TAB_JS).
|
|
1721
|
+
const link = target.closest('a[target]');
|
|
1722
|
+
if (link && (link.getAttribute('target') || '').toLowerCase() === '_blank') link.setAttribute('target', '_self');
|
|
1494
1723
|
target.click();
|
|
1495
1724
|
return detail;
|
|
1496
1725
|
}
|
|
@@ -347,6 +347,9 @@ class DownloadResult:
|
|
|
347
347
|
fulltext_page: dict[str, Any] = field(default_factory=dict)
|
|
348
348
|
#: Where a login that waited on the user ended (``_login_wait_page``).
|
|
349
349
|
login_wait_page: str = ""
|
|
350
|
+
#: The kind of the last verification page this item waited on (a key of
|
|
351
|
+
#: ``browser.challenge.kinds.LABELS``), for the record (``_note_challenge_type``).
|
|
352
|
+
challenge_type: str = ""
|
|
350
353
|
#: How the browser of this item started: who held its profile, the wait for
|
|
351
354
|
#: it, the launch's seconds, a relaunch (``_launch_context``).
|
|
352
355
|
browser_start: dict[str, Any] = field(default_factory=dict)
|
|
@@ -84,12 +84,12 @@ class DiagnosticsMixin:
|
|
|
84
84
|
# choosing the school the page is not waiting for the user (JBJS on
|
|
85
85
|
# OpenAthens, 2026-11-06: five remembered-school clicks in 25 s, no
|
|
86
86
|
# main-frame navigation, and a "no progress" reminder in between).
|
|
87
|
-
"sso_entry_clicked", "openathens_entry", "seamlessaccess_chooser_opened",
|
|
87
|
+
"sso_entry_clicked", "sso_entry_opened", "openathens_entry", "seamlessaccess_chooser_opened",
|
|
88
88
|
"auto_remembered_entry", "institution_selected", "auto_institution_search",
|
|
89
89
|
"institution_search_submitted", "institution_search_retyped",
|
|
90
90
|
"institution_list_submitted", "institution_continue",
|
|
91
91
|
"login_round_trip_returned", "redirect_page_passed",
|
|
92
|
-
"publisher_terms_accepted", "idp_confirmation_accepted", "personal_account_offer_skipped",
|
|
92
|
+
"publisher_terms_accepted", "download_terms_agreed", "idp_confirmation_accepted", "personal_account_offer_skipped",
|
|
93
93
|
}:
|
|
94
94
|
activity.progress()
|
|
95
95
|
# Only publish fixed phase text; event details can contain signed URLs.
|
|
@@ -103,6 +103,7 @@ class DiagnosticsMixin:
|
|
|
103
103
|
"idp_confirmation_required": ("请在浏览器里确认学校认证页的提示(信息发送同意、使用条款或二次验证)", "waiting_login"),
|
|
104
104
|
"idp_confirmation_accepted": ("已确认学校认证页的提示", "checking_access"),
|
|
105
105
|
"publisher_terms_accepted": ("已同意出版社的条款", "checking_access"),
|
|
106
|
+
"download_terms_agreed": ("已勾选同意网站的下载条款", "fetching_pdf"),
|
|
106
107
|
"login_attempt_started": ("正在尝试机构登录", "checking_access"),
|
|
107
108
|
"login_retry_wait": ("机构登录暂未完成,准备重试", "checking_access"),
|
|
108
109
|
"login_navigation_interrupted": ("登录跳转中断,检查是否可重试", "checking_access"),
|
|
@@ -204,6 +205,20 @@ class DiagnosticsMixin:
|
|
|
204
205
|
if result is not None and took > self.LONG_WAIT_SEC:
|
|
205
206
|
self._event(result, "wait", f"{what}: {took:.0f} s, ended: {why}")
|
|
206
207
|
|
|
208
|
+
def _note_challenge_type(self, page: Any, result: DownloadResult, *, title_and_url_only: bool = False) -> None:
|
|
209
|
+
"""Which kind of verification the page is (``browser.challenge.kinds``), in the
|
|
210
|
+
record: an event when it is first seen or changes (a reCAPTCHA box that asks its
|
|
211
|
+
picture puzzle), and ``result.challenge_type``, which the failure record and the
|
|
212
|
+
CLI's summary name (the user, 2026-11-25). Only read, never acted on."""
|
|
213
|
+
from ..browser.challenge import kinds
|
|
214
|
+
|
|
215
|
+
kind = kinds.identify(page, title_and_url_only=title_and_url_only)
|
|
216
|
+
if kind == "other" and result.challenge_type:
|
|
217
|
+
return # a later look that tells less keeps what an earlier one told
|
|
218
|
+
if kind != result.challenge_type:
|
|
219
|
+
result.challenge_type = kind
|
|
220
|
+
self._event(result, "challenge_type", f"{kind}: {kinds.LABELS[kind]}")
|
|
221
|
+
|
|
207
222
|
def _write_diagnostic(self, page: Any, result: DownloadResult, run_dir: Path) -> None:
|
|
208
223
|
diag_dir = run_dir / "diagnostics" / safe_name(result.doi)
|
|
209
224
|
diag_dir.mkdir(parents=True, exist_ok=True)
|
|
@@ -249,14 +264,19 @@ class DiagnosticsMixin:
|
|
|
249
264
|
result.diagnostic_path = str(packet_path)
|
|
250
265
|
|
|
251
266
|
def _denial_line(self, page: Any) -> str:
|
|
252
|
-
"""The page's denial (access_rules.denial_evidence)
|
|
253
|
-
why it is the school's: ``denial line: "<the page's words>"
|
|
254
|
-
item's school login)``."""
|
|
267
|
+
"""The page's denial (access_rules.denial_evidence), else its offer, for the
|
|
268
|
+
diagnostic, and why it is the school's: ``denial line: "<the page's words>"
|
|
269
|
+
(after this item's school login)``."""
|
|
255
270
|
try:
|
|
256
271
|
snap = self._access_snapshot(page)
|
|
257
272
|
except Exception:
|
|
258
273
|
return "" # a probe for the diagnostic; the failure is reported either way
|
|
259
274
|
evidence, named = access_rules.denial_evidence(snap.url, snap.lines, snap.probe)
|
|
275
|
+
if not evidence:
|
|
276
|
+
# An offer decided, the school signed in (``_no_access_after_login``: NEJM Catalyst's
|
|
277
|
+
# "Get Access", Taylor & Francis's "Purchase options"): its words, not "nothing saved".
|
|
278
|
+
offer = access_rules.offer_evidence(snap.lines, snap.probe, gate=False)
|
|
279
|
+
evidence = f'offer: "{offer}"' if offer else ""
|
|
260
280
|
if not evidence:
|
|
261
281
|
return ""
|
|
262
282
|
try:
|