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.
Files changed (204) hide show
  1. package/NOTICE +8 -37
  2. package/README.fr.md +265 -0
  3. package/README.ja.md +265 -0
  4. package/README.ko.md +265 -0
  5. package/README.md +149 -148
  6. package/README.zh-Hant.md +265 -0
  7. package/README.zh.md +265 -0
  8. package/dist/capabilities/download/batch/batch.d.ts +20 -1
  9. package/dist/capabilities/download/batch/batch.d.ts.map +1 -1
  10. package/dist/capabilities/download/batch/batch.js +1057 -208
  11. package/dist/capabilities/download/batch/batch.js.map +1 -1
  12. package/dist/capabilities/download/batch/batchFolder.d.ts.map +1 -1
  13. package/dist/capabilities/download/batch/batchFolder.js +3 -2
  14. package/dist/capabilities/download/batch/batchFolder.js.map +1 -1
  15. package/dist/capabilities/download/batch/networkLoss.d.ts +11 -2
  16. package/dist/capabilities/download/batch/networkLoss.d.ts.map +1 -1
  17. package/dist/capabilities/download/batch/networkLoss.js +24 -3
  18. package/dist/capabilities/download/batch/networkLoss.js.map +1 -1
  19. package/dist/capabilities/download/batch/resume.d.ts +7 -0
  20. package/dist/capabilities/download/batch/resume.d.ts.map +1 -1
  21. package/dist/capabilities/download/batch/resume.js +50 -9
  22. package/dist/capabilities/download/batch/resume.js.map +1 -1
  23. package/dist/capabilities/download/batch/windowPlan.d.ts +96 -0
  24. package/dist/capabilities/download/batch/windowPlan.d.ts.map +1 -0
  25. package/dist/capabilities/download/batch/windowPlan.js +196 -0
  26. package/dist/capabilities/download/batch/windowPlan.js.map +1 -0
  27. package/dist/capabilities/download/content/markdown/pro.d.ts +6 -0
  28. package/dist/capabilities/download/content/markdown/pro.d.ts.map +1 -1
  29. package/dist/capabilities/download/content/markdown/pro.js.map +1 -1
  30. package/dist/capabilities/download/content/markdown/shortfall.d.ts +8 -5
  31. package/dist/capabilities/download/content/markdown/shortfall.d.ts.map +1 -1
  32. package/dist/capabilities/download/content/markdown/shortfall.js +22 -10
  33. package/dist/capabilities/download/content/markdown/shortfall.js.map +1 -1
  34. package/dist/capabilities/download/content/markdown/step.d.ts +9 -0
  35. package/dist/capabilities/download/content/markdown/step.d.ts.map +1 -1
  36. package/dist/capabilities/download/content/markdown/step.js +46 -3
  37. package/dist/capabilities/download/content/markdown/step.js.map +1 -1
  38. package/dist/capabilities/download/content/markdown/types.d.ts +10 -1
  39. package/dist/capabilities/download/content/markdown/types.d.ts.map +1 -1
  40. package/dist/capabilities/download/content/pdf/open/tiers/scihub.d.ts.map +1 -1
  41. package/dist/capabilities/download/content/pdf/open/tiers/scihub.js +3 -1
  42. package/dist/capabilities/download/content/pdf/open/tiers/scihub.js.map +1 -1
  43. package/dist/capabilities/download/handler.d.ts.map +1 -1
  44. package/dist/capabilities/download/handler.js +13 -5
  45. package/dist/capabilities/download/handler.js.map +1 -1
  46. package/dist/capabilities/download/outputLayout.d.ts.map +1 -1
  47. package/dist/capabilities/download/outputLayout.js +3 -1
  48. package/dist/capabilities/download/outputLayout.js.map +1 -1
  49. package/dist/capabilities/download/tools.js +2 -2
  50. package/dist/capabilities/download/tools.js.map +1 -1
  51. package/dist/capabilities/download/types.d.ts +9 -1
  52. package/dist/capabilities/download/types.d.ts.map +1 -1
  53. package/dist/cli.js +3 -1
  54. package/dist/cli.js.map +1 -1
  55. package/dist/infrastructure/http/hostGate.d.ts +24 -0
  56. package/dist/infrastructure/http/hostGate.d.ts.map +1 -0
  57. package/dist/infrastructure/http/hostGate.js +72 -0
  58. package/dist/infrastructure/http/hostGate.js.map +1 -0
  59. package/dist/infrastructure/pdf/PdfDownload.d.ts +1 -0
  60. package/dist/infrastructure/pdf/PdfDownload.d.ts.map +1 -1
  61. package/dist/infrastructure/pdf/PdfDownload.js +6 -1
  62. package/dist/infrastructure/pdf/PdfDownload.js.map +1 -1
  63. package/dist/infrastructure/runlog/RunLedger.d.ts +14 -0
  64. package/dist/infrastructure/runlog/RunLedger.d.ts.map +1 -1
  65. package/dist/infrastructure/runlog/RunLedger.js +30 -4
  66. package/dist/infrastructure/runlog/RunLedger.js.map +1 -1
  67. package/dist/infrastructure/runlog/failureClass.d.ts +2 -1
  68. package/dist/infrastructure/runlog/failureClass.d.ts.map +1 -1
  69. package/dist/infrastructure/runlog/failureClass.js +27 -4
  70. package/dist/infrastructure/runlog/failureClass.js.map +1 -1
  71. package/dist/infrastructure/school/SchoolAttempt.d.ts +11 -0
  72. package/dist/infrastructure/school/SchoolAttempt.d.ts.map +1 -1
  73. package/dist/infrastructure/school/SchoolAttempt.js +48 -5
  74. package/dist/infrastructure/school/SchoolAttempt.js.map +1 -1
  75. package/dist/infrastructure/school/SchoolMcpClient.d.ts +13 -2
  76. package/dist/infrastructure/school/SchoolMcpClient.d.ts.map +1 -1
  77. package/dist/infrastructure/school/SchoolMcpClient.js +138 -15
  78. package/dist/infrastructure/school/SchoolMcpClient.js.map +1 -1
  79. package/dist/infrastructure/school/SchoolProgress.d.ts +2 -0
  80. package/dist/infrastructure/school/SchoolProgress.d.ts.map +1 -1
  81. package/dist/infrastructure/school/SchoolProgress.js +2 -0
  82. package/dist/infrastructure/school/SchoolProgress.js.map +1 -1
  83. package/dist/infrastructure/school/SchoolReadiness.d.ts +9 -0
  84. package/dist/infrastructure/school/SchoolReadiness.d.ts.map +1 -1
  85. package/dist/infrastructure/school/SchoolReadiness.js +10 -0
  86. package/dist/infrastructure/school/SchoolReadiness.js.map +1 -1
  87. package/dist/infrastructure/school/SchoolResultNormalizer.d.ts.map +1 -1
  88. package/dist/infrastructure/school/SchoolResultNormalizer.js +4 -0
  89. package/dist/infrastructure/school/SchoolResultNormalizer.js.map +1 -1
  90. package/dist/infrastructure/school/index.d.ts +2 -2
  91. package/dist/infrastructure/school/index.d.ts.map +1 -1
  92. package/dist/infrastructure/school/index.js +1 -1
  93. package/dist/infrastructure/school/index.js.map +1 -1
  94. package/dist/infrastructure/school/types.d.ts +73 -1
  95. package/dist/infrastructure/school/types.d.ts.map +1 -1
  96. package/dist/infrastructure/school/types.js.map +1 -1
  97. package/dist/infrastructure/security/SecurityUtils.d.ts.map +1 -1
  98. package/dist/infrastructure/security/SecurityUtils.js +6 -2
  99. package/dist/infrastructure/security/SecurityUtils.js.map +1 -1
  100. package/dist/management/failures/index.d.ts +23 -0
  101. package/dist/management/failures/index.d.ts.map +1 -1
  102. package/dist/management/failures/index.js +68 -20
  103. package/dist/management/failures/index.js.map +1 -1
  104. package/dist/management/school/autoUpdate.d.ts.map +1 -1
  105. package/dist/management/school/autoUpdate.js +9 -1
  106. package/dist/management/school/autoUpdate.js.map +1 -1
  107. package/dist/management/school/cliProgress.d.ts.map +1 -1
  108. package/dist/management/school/cliProgress.js +3 -1
  109. package/dist/management/school/cliProgress.js.map +1 -1
  110. package/package.json +8 -3
  111. package/school/NOTICE +3 -2
  112. package/school/paper_search_school/adapters/__init__.py +2 -0
  113. package/school/paper_search_school/adapters/aps/__init__.py +3 -6
  114. package/school/paper_search_school/adapters/base.py +19 -2
  115. package/school/paper_search_school/adapters/copernicus/__init__.py +2 -7
  116. package/school/paper_search_school/adapters/elsevier/__init__.py +50 -1
  117. package/school/paper_search_school/adapters/frontiers/__init__.py +41 -2
  118. package/school/paper_search_school/adapters/ieee/__init__.py +6 -4
  119. package/school/paper_search_school/adapters/iop/__init__.py +8 -0
  120. package/school/paper_search_school/adapters/jama/__init__.py +8 -0
  121. package/school/paper_search_school/adapters/lww/__init__.py +14 -6
  122. package/school/paper_search_school/adapters/mdpi/__init__.py +12 -7
  123. package/school/paper_search_school/adapters/neurology/__init__.py +5 -2
  124. package/school/paper_search_school/adapters/optica/__init__.py +52 -13
  125. package/school/paper_search_school/adapters/oup/__init__.py +7 -4
  126. package/school/paper_search_school/adapters/platforms/__init__.py +4 -1
  127. package/school/paper_search_school/adapters/platforms/atypon/__init__.py +12 -3
  128. package/school/paper_search_school/adapters/platforms/figshare/__init__.py +23 -4
  129. package/school/paper_search_school/adapters/platforms/jstage/__init__.py +64 -0
  130. package/school/paper_search_school/adapters/taylor_francis/__init__.py +0 -3
  131. package/school/paper_search_school/adapters/thieme/__init__.py +2 -9
  132. package/school/paper_search_school/api_keys.py +63 -13
  133. package/school/paper_search_school/assets/api_keys.json +14 -0
  134. package/school/paper_search_school/assets/capsule.html +526 -147
  135. package/school/paper_search_school/assets/capsule_en.json +140 -49
  136. package/school/paper_search_school/assets/capsule_fr.json +141 -50
  137. package/school/paper_search_school/assets/capsule_ja.json +140 -49
  138. package/school/paper_search_school/assets/capsule_ko.json +140 -49
  139. package/school/paper_search_school/assets/capsule_zh-Hant.json +134 -48
  140. package/school/paper_search_school/browser/backend.py +125 -4
  141. package/school/paper_search_school/browser/batch_session.py +189 -8
  142. package/school/paper_search_school/browser/challenge/__init__.py +12 -9
  143. package/school/paper_search_school/browser/challenge/continuation.py +83 -0
  144. package/school/paper_search_school/browser/challenge/handlers/__init__.py +1 -0
  145. package/school/paper_search_school/browser/challenge/handlers/aws_waf.py +260 -0
  146. package/school/paper_search_school/browser/challenge/handlers/recaptcha_hcaptcha.py +167 -0
  147. package/school/paper_search_school/browser/challenge/handlers/text_captcha.py +128 -0
  148. package/school/paper_search_school/browser/challenge/handlers/turnstile.py +174 -0
  149. package/school/paper_search_school/browser/challenge/kinds.py +203 -0
  150. package/school/paper_search_school/browser/challenge/local/__init__.py +1 -0
  151. package/school/paper_search_school/browser/challenge/{interaction.py → local/interaction.py} +94 -13
  152. package/school/paper_search_school/browser/challenge/{pointer.py → local/pointer.py} +2 -2
  153. package/school/paper_search_school/browser/challenge/local/prompt.py +283 -0
  154. package/school/paper_search_school/browser/challenge/local/submission.py +33 -0
  155. package/school/paper_search_school/browser/challenge/pro.py +24 -0
  156. package/school/paper_search_school/browser/challenge/services/__init__.py +1 -0
  157. package/school/paper_search_school/browser/challenge/services/solver.py +292 -0
  158. package/school/paper_search_school/browser/engine.py +4 -1
  159. package/school/paper_search_school/browser/user_turn.py +126 -0
  160. package/school/paper_search_school/browser/watchdog.py +213 -60
  161. package/school/paper_search_school/cli_config.py +10 -5
  162. package/school/paper_search_school/config.py +16 -10
  163. package/school/paper_search_school/download_diagnostics.py +7 -2
  164. package/school/paper_search_school/engine/access_rules.py +12 -3
  165. package/school/paper_search_school/engine/batch.py +52 -18
  166. package/school/paper_search_school/engine/batch_access.py +62 -16
  167. package/school/paper_search_school/engine/batch_capture.py +260 -31
  168. package/school/paper_search_school/engine/batch_common.py +3 -0
  169. package/school/paper_search_school/engine/batch_diagnostics.py +25 -5
  170. package/school/paper_search_school/engine/batch_institution.py +52 -3
  171. package/school/paper_search_school/engine/batch_login.py +398 -36
  172. package/school/paper_search_school/engine/batch_pdf_urls.py +38 -7
  173. package/school/paper_search_school/engine/batch_user.py +48 -3
  174. package/school/paper_search_school/engine/batch_waits.py +221 -14
  175. package/school/paper_search_school/engine/bridge.py +29 -6
  176. package/school/paper_search_school/engine/fulltext_page.py +55 -8
  177. package/school/paper_search_school/engine/router.py +16 -1
  178. package/school/paper_search_school/engine/supplements.py +7 -1
  179. package/school/paper_search_school/entitlements.py +29 -1
  180. package/school/paper_search_school/pdf_utils.py +25 -16
  181. package/school/paper_search_school/progress_capsule.py +69 -11
  182. package/school/paper_search_school/progress_reporter.py +243 -11
  183. package/school/paper_search_school/progress_view.py +205 -91
  184. package/school/paper_search_school/publishers/builtin/iop.json +2 -1
  185. package/school/paper_search_school/publishers/builtin/neurology.json +4 -2
  186. package/school/paper_search_school/publishers/site.py +12 -4
  187. package/school/paper_search_school/rate_limit.py +24 -1
  188. package/school/paper_search_school/school_login.py +170 -8
  189. package/school/paper_search_school/school_test.py +1 -1
  190. package/school/paper_search_school/server.py +179 -23
  191. package/school/paper_search_school/user_settings.py +46 -4
  192. package/school/pyproject.toml +1 -0
  193. package/skills/paper-search/SKILL.md +107 -107
  194. package/skills/paper-search/references/browser-download.md +102 -99
  195. package/skills/paper-search/references/capability-routing.md +89 -89
  196. package/skills/paper-search/references/cli-contract.md +78 -78
  197. package/skills/paper-search/references/federation-support.md +172 -172
  198. package/skills/paper-search/references/management-layer.md +78 -78
  199. package/skills/paper-search/references/publisher-support.md +38 -38
  200. package/skills/paper-search/references/school-setup.md +56 -55
  201. package/skills/paper-search/references/setup.md +20 -20
  202. package/skills/paper-search/references/troubleshooting.md +12 -12
  203. package/README.en.md +0 -264
  204. package/school/paper_search_school/browser/challenge/prompt.py +0 -154
@@ -30,11 +30,22 @@ NO_INSTITUTION_ENTRY = "no_institution_entry"
30
30
 
31
31
 
32
32
  # PaperSearch Pro's school sign-in (school_login.py): the reminder when it leaves a step to the user.
33
+ #: How long the captcha service may take over one image code on a school's sign-in page (its form waits).
34
+ SCHOOL_CODE_SEC = 30.0
33
35
  SIGN_IN_REFUSED = "学校没有接受保存的密码,自动登录已关闭:请在浏览器窗口完成机构登录,并在设置里更新密码"
34
36
  SIGN_IN_SECOND_STEP = "学校还要再验证一步(如微信扫码),请在浏览器窗口完成"
35
37
  SIGN_IN_FOR_THE_USER = "学校登录页要你本人操作(验证码、扫码或另一个账号),请在浏览器窗口完成"
36
38
  #: A school's login page whose certificate Chrome will not take, and not the one Pro's survey saw there.
37
39
  SIGN_IN_CERTIFICATE = "学校登录页的证书和之前记下的不一样,没有自动填写:请确认是学校的网站后,在浏览器窗口完成机构登录"
40
+ #: Every school is tried, tested or not (user, 2026-11-28: what fails is told, never decided for the user in advance);
41
+ #: what kept it from being filled in, said to the user. The next sign-in tries again; only a wrong password stops it.
42
+ SIGN_IN_NO_FORM = "学校登录页上没认出账号密码框,没有自动填写:请在浏览器窗口完成机构登录"
43
+ SIGN_IN_UNCLEAR = "学校登录页的表单不明确(有几个密码框),没有自动填写:请在浏览器窗口完成机构登录"
44
+ SIGN_IN_NO_REPLY = "已自动填写并提交,但学校没有说账号是否正确(可能是学校服务器出错或网络问题):请在浏览器窗口检查,需要的话自己登录"
45
+ SIGN_IN_UNTRUSTED = "学校登录页的证书有问题(过期或不受信任),没有自动填写:请确认是学校的网站后,在浏览器窗口完成机构登录"
46
+ SIGN_IN_HOURLY = "这所学校一小时内自动填写的次数已满,这次没有填写:请在浏览器窗口完成机构登录"
47
+ #: A sign-in page with no form read for this long is said to have none (a page still being drawn is not).
48
+ NO_FORM_NOTE_SEC = 8.0
38
49
  #: The note naming the check the school's page asks for (Pro's school sign-in tells which, 2026-11-19).
39
50
  SIGN_IN_ASKS = {
40
51
  "image_code": "学校登录页要输入图片验证码,请在浏览器窗口完成",
@@ -44,9 +55,31 @@ SIGN_IN_ASKS = {
44
55
  "qr_scan": "学校登录页要扫码,请在浏览器窗口完成",
45
56
  "site_check": "学校登录页要完成人机检查,请在浏览器窗口完成",
46
57
  "second_factor": "学校还要二次验证,请在浏览器窗口完成",
58
+ # Pro's site_refused (2026-11-28): the sent form turned away by the school's site, no word about the account.
59
+ "site_refused": "学校网站的安全防护拦下了这次自动登录,请在浏览器窗口自己登录",
47
60
  }
48
61
 
49
62
 
63
+ def _school_code_ask(config: dict, budget: Any, say: Any) -> Any:
64
+ """Give Pro a budgeted transport for the user's configured image service.
65
+
66
+ Only image bytes and task options cross this boundary, never form fields.
67
+ """
68
+ from ..browser.challenge.services import solver
69
+
70
+ if not solver.configured(config):
71
+ return None
72
+ seconds = min(SCHOOL_CODE_SEC, float(config.get("captcha_timeout") or SCHOOL_CODE_SEC))
73
+
74
+ def ask(image: bytes, **options: Any) -> str:
75
+ if budget is not None and not budget.take():
76
+ say("image code: the captcha service's budget for this run is used up")
77
+ return ""
78
+ return str(solver.solve_image(image, config, timeout=seconds, **options) or "")
79
+
80
+ return ask
81
+
82
+
50
83
  class LoginMixin:
51
84
  """Institution login: the publisher's sign-in entry, a login on another site, SSO, waiting for the login to finish."""
52
85
 
@@ -96,11 +129,13 @@ class LoginMixin:
96
129
  # or looking for an institution entry that cannot exist on it.
97
130
  if not self._wait_for_challenge(page, result):
98
131
  return False
132
+ self._note_article_host(page)
99
133
  self._raise_on_publisher_content_error(page)
100
134
  self._dismiss_cookie_banners(page, result)
101
135
  snapshot = self._access_snapshot(page) if not self._is_auth_page(str(page.url)) else None
102
136
  if snapshot is not None and self._ip_blocked_text(snapshot.text):
103
137
  # Science, 2026-11-16: the driver went on to the school's login and waited out its time.
138
+ self._event(result, "ip_blocked_page", self._ip_blocked_words(snapshot.text)[:240])
104
139
  raise PublisherAccessBlocked("publisher_access_blocked")
105
140
  if self._institution_pdf_entitlement_missing(page, snapshot=snapshot):
106
141
  return False
@@ -223,12 +258,20 @@ class LoginMixin:
223
258
  def _wait_past_redirect_page(self, page: Any, result: DownloadResult, timeout_sec: float = 20) -> None:
224
259
  """Let a publisher's script redirect page (linkinghub "Redirecting") move on
225
260
  before the access check: it is neither the article nor a login page. A
226
- verification shown there is waited for by the challenge wait instead."""
261
+ verification shown there is waited for by the challenge wait instead, and a
262
+ page saying the site throttles or blocks this address, at the redirect's own
263
+ address (Optica's reader, 2026-11-26), is not waited on: the access check
264
+ reads it as such."""
227
265
  started = time.time()
228
266
  deadline = started + timeout_sec
229
267
  waited = False
268
+ looked = started # a look at the page's words once a second, the first after a second
230
269
  while (self.adapter.is_redirect_page(str(getattr(page, "url", "") or "")) and time.time() < deadline
231
270
  and not self._challenge_shell(page)):
271
+ if time.time() - looked >= 1:
272
+ looked = time.time()
273
+ if self._ip_blocked_text(self._body_text(page, 20_000)):
274
+ break
232
275
  waited = True
233
276
  page.wait_for_timeout(POLL_MS)
234
277
  if waited:
@@ -237,9 +280,11 @@ class LoginMixin:
237
280
 
238
281
  def _reopen_after_gateway_error(self, page: Any, result: DownloadResult) -> None:
239
282
  """Open the article again, once, when the publisher's front proxy answered
240
- with its bare error page instead (its server did not answer in time). The
241
- same page again is the publisher's error, reported as such."""
242
- error = self._gateway_error_text(page)
283
+ with its bare error page instead (its server did not answer in time), or the
284
+ site with its own page for a fault on its side (the adapter's
285
+ ``server_error_page``). The same page again is the publisher's error,
286
+ reported as such."""
287
+ error = self._server_error_text(page)
243
288
  if not error:
244
289
  return
245
290
  self._event(result, "gateway_error_page", error[:160])
@@ -247,10 +292,13 @@ class LoginMixin:
247
292
  open_page(page, result.article_url, timeout_ms=60_000)
248
293
  settle(page, 3_000)
249
294
  self._wait_past_redirect_page(page, result)
250
- error = self._gateway_error_text(page)
295
+ error = self._server_error_text(page)
251
296
  if error:
252
297
  raise PublisherContentError(f"publisher_gateway_error: {error[:120]}")
253
298
 
299
+ def _server_error_text(self, page: Any) -> str:
300
+ return self._gateway_error_text(page) or self.adapter.server_error_page(page)
301
+
254
302
  def _complete_login_from_current_page(self, page: Any, result: DownloadResult) -> bool:
255
303
  """The school's login from the current page (``_complete_login_steps``), then
256
304
  back to the article if it ended on another page (``_return_to_article_after_login``);
@@ -265,15 +313,21 @@ class LoginMixin:
265
313
  result._visited_idp = True
266
314
 
267
315
  page.on("framenavigated", observe_login_navigation)
316
+ turn = False
268
317
  try:
269
318
  from ..browser import watchdog
270
319
  # Human authentication has its own budget, not the automation's.
271
320
  with watchdog.pause_operation():
321
+ # Another window at the school's login or a verification first (并行下载): this one waits for its
322
+ # turn before it opens the school's login, then goes through on the login the other one made.
323
+ turn = self._take_user_turn(page, result) is not None
272
324
  signed_in = self._complete_login_steps(page, result)
273
325
  if signed_in:
274
326
  self._return_to_article_after_login(page, result)
275
327
  return signed_in
276
328
  finally:
329
+ if turn:
330
+ self._give_user_turn()
277
331
  page.remove_listener("framenavigated", observe_login_navigation)
278
332
  self._set_login_attention(result, "")
279
333
  last = next((e["state"] for e in reversed(result.events) if e["state"] != "wait"), "")
@@ -403,21 +457,57 @@ class LoginMixin:
403
457
 
404
458
  def _school_sign_in(self, page: Any, result: DownloadResult) -> bool:
405
459
  """PaperSearch Pro fills the school's sign-in in for the user (its tests and survey in the Pro repository):
406
- on the school's own https page, for a school Pro has tested, with the account the user
460
+ on the school's own https page, for any school (tested or not, user 2026-11-28), with the account the user
407
461
  saved, once a paper and at most school_login.PER_HOUR times an hour. True when the form
408
- was sent. A wrong password turns it off for the school: the user signs in and saves the
462
+ was sent. What keeps it from filling in is said to the user (_sign_in_note); the next paper tries again.
463
+ A wrong password turns it off for the school: the user signs in and saves the
409
464
  account again. Never the account in an event."""
410
465
  from .. import school_login
411
466
 
412
467
  if os.environ.get(school_login.SURVEY_ENV) in {"1", "press"}:
413
468
  return self._school_sign_in_survey(page, result)
414
- if getattr(result, "_sign_in_tried", False):
415
- return False
416
469
  entity_id = str(self.config.get("idp_entity_id") or "").strip()
417
470
  account = school_login.saved(self.config, entity_id)
418
- pro = school_login.module() if account and account.get("enabled") else None
471
+ pro = school_login.module()
419
472
  if pro is None:
420
- return False # no account to fill in, turned off, or no Pro: the user signs in as before
473
+ return False
474
+ continuation = getattr(result, "_sign_in_continuation", None)
475
+ if not hasattr(result, "_sign_in_continuation"):
476
+ factory = getattr(pro, "entry_continuation", None)
477
+ continuation = factory(entity_id) if callable(factory) else None
478
+ result._sign_in_continuation = continuation
479
+ resume = False
480
+ inspector = getattr(pro, "inspect_entry", None)
481
+ if callable(inspector) and (self._login_wait_page(page) == "school_login" or getattr(result, "_visited_idp", False)):
482
+ also = school_login.pro_login_hosts(pro, entity_id) + tuple(sorted(getattr(self, "_shared_from_school", ()) or ()))
483
+ plain = school_login.pro_plain_hosts(pro, entity_id)
484
+ allowed = lambda address: school_login.may_fill(address, self.config, also, plain)
485
+ address = str(getattr(page, "url", "") or "")
486
+ probed = getattr(result, "_entry_probed", frozenset())
487
+ switched = []
488
+ blocked = inspector(page, allowed, school=entity_id, switch=address not in probed,
489
+ on_switch=switched.append)
490
+ if continuation is not None:
491
+ resume = continuation.observe(page, allowed, tried=getattr(result, "_sign_in_tried", False),
492
+ blocked=blocked)
493
+ # A loading page with no candidate has not used its switch budget.
494
+ # Only an actual attempt makes this URL ineligible for another three-step search.
495
+ if switched:
496
+ result._entry_probed = probed | {address}
497
+ if blocked:
498
+ detail = "qr(" + str(blocked.get("app") or "") + ")" if blocked.get("entry") == "qr_only" else "sms"
499
+ if blocked.get("sms_alternative"):
500
+ detail += ",sms"
501
+ if detail != getattr(result, "_school_page_blocked", ""):
502
+ self._event(result, "school_page_blocked", detail)
503
+ result._school_page_blocked = detail
504
+ result._sign_in_note = school_login.entry_notice(blocked)
505
+ return False
506
+ if getattr(result, "_school_page_blocked", ""):
507
+ result._school_page_blocked = ""
508
+ result._sign_in_note = ""
509
+ if not account or not account.get("enabled") or (getattr(result, "_sign_in_tried", False) and not resume):
510
+ return False
421
511
 
422
512
  def skipped(why: str) -> bool:
423
513
  # Why nothing was filled in, once a paper for each reason: what a school's test reads
@@ -431,21 +521,33 @@ class LoginMixin:
431
521
  if not school_login.fills_for(entity_id, pro):
432
522
  return skipped(f"not tested: {school_login.school_status(entity_id, pro) or 'not listed'}")
433
523
  url = str(getattr(page, "url", "") or "")
434
- also = school_login.pro_login_hosts(pro, entity_id) # its login page on another domain of its own
435
- if not school_login.may_fill(url, self.config, also) and not (
436
- self._fill_school_places(entity_id) and school_login.may_fill(url, self.config, also)):
524
+ also = school_login.pro_login_hosts(pro, entity_id) + tuple(sorted(getattr(self, "_shared_from_school", ()) or ())) # its login page on another domain of its own
525
+ plain = school_login.pro_plain_hosts(pro, entity_id) # its login page on plain http, as its survey found
526
+ if not school_login.may_fill(url, self.config, also, plain) and not (
527
+ self._fill_school_places(entity_id) and school_login.may_fill(url, self.config, also, plain)):
437
528
  return skipped(f"not the school's page: {urlparse(url).scheme}://{urlparse(url).hostname or ''}")
438
529
  kind = self._login_wait_page(page)
439
530
  if kind != "school_login":
440
531
  return skipped(f"not a sign-in page: {kind}")
441
532
  if self._idp_confirmation(page):
442
533
  return False # the school's consent or terms: agreed to by _accept_idp_confirmation, no form
443
- allowed = lambda address: school_login.may_fill(address, self.config, also) # noqa: E731
534
+ allowed = lambda address: school_login.may_fill(address, self.config, also, plain) # noqa: E731
535
+ strict_reply = bool(school_login.entry_for(entity_id, pro))
536
+ if strict_reply and not pro.entry_ready(page, allowed, school=entity_id):
537
+ return skipped("waiting for the account and password form")
444
538
  try:
445
539
  if not pro.ready(page, allowed, school=entity_id):
446
- # A consent page, a chooser, a form already being typed in: what Pro saw.
540
+ # A consent page, a chooser, a form already being typed in: what Pro saw. Said to the user once the
541
+ # page has shown none for NO_FORM_NOTE_SEC (a page still being drawn is not one without a form).
542
+ since = getattr(result, "_sign_in_no_form_since", 0.0) or time.time()
543
+ result._sign_in_no_form_since = since
544
+ if time.time() - since >= NO_FORM_NOTE_SEC and not getattr(result, "_sign_in_tried", False):
545
+ result._sign_in_note = SIGN_IN_NO_FORM
447
546
  describe = getattr(pro, "describe", None)
448
547
  return skipped("no form to fill: " + (describe(page, allowed, school=entity_id) if describe else "?"))
548
+ result._sign_in_no_form_since = 0.0
549
+ if getattr(result, "_sign_in_note", "") == SIGN_IN_NO_FORM:
550
+ result._sign_in_note = "" # the form has come since
449
551
  except Exception as exc:
450
552
  if not _is_browser_error(exc):
451
553
  raise
@@ -456,21 +558,37 @@ class LoginMixin:
456
558
  error, digest = school_login.page_certificate(page)
457
559
  if not school_login.certificate_allows(urlparse(url).hostname or "", error, digest, pins):
458
560
  result._sign_in_tried = True
459
- if digest and pins:
460
- result._sign_in_note = SIGN_IN_CERTIFICATE
561
+ result._sign_in_note = SIGN_IN_CERTIFICATE if digest and pins else SIGN_IN_UNTRUSTED
461
562
  return skipped(f"certificate not taken: {error or 'unread'}")
462
563
  result._sign_in_tried = True
564
+ if continuation is not None:
565
+ continuation.consume()
463
566
  if not school_login.take_turn(entity_id):
464
567
  self._event(result, "school_sign_in", f"not filled: {school_login.PER_HOUR} in the last hour")
568
+ result._sign_in_note = SIGN_IN_HOURLY
465
569
  return False
466
570
  secrets = (str(account["password"]), str(account["username"]))
467
571
  attempt = school_login.Attempt(
468
572
  username=str(account["username"]), password=str(account["password"]), allowed=allowed,
469
573
  event=lambda state, detail="": self._event(result, state, school_login.hide(str(detail), secrets)),
470
- hidden=secrets, school=entity_id)
574
+ hidden=secrets, school=entity_id, strict_reply=strict_reply,
575
+ ask_code=_school_code_ask(self.config, getattr(self, "_captcha_budget", None),
576
+ lambda detail: self._event(result, "school_sign_in_step", detail)),
577
+ # A reCAPTCHA, hCaptcha or Turnstile box on the school's page: the publishers' handlers (user, 2026-11-28).
578
+ pass_check=school_login.check_passer(self.config, getattr(self, "_captcha_budget", None),
579
+ lambda detail: self._event(result, "school_challenge", detail),
580
+ lambda: self._check_user_decision(result, page)),
581
+ # A sign-in chooser's way, picked in the progress window once and pressed again after (user, 2026-11-29).
582
+ way=str(account.get("way") or ""),
583
+ choose_way=self._choose_way(page, result, str(self.config.get("school_name") or "")),
584
+ remember_way=lambda way: school_login.set_way(entity_id, way))
471
585
  try:
472
586
  outcome = str(pro.sign_in(page, attempt) or "failed")
473
587
  except Exception as exc:
588
+ from ..entitlements import UserMarkedNoEntitlement
589
+ from ..browser import watchdog as browser_watchdog
590
+ if isinstance(exc, (UserMarkedNoEntitlement, browser_watchdog.BrowserUnresponsive)):
591
+ raise # the user's decision during a box's check (pass_check), or the browser gone: not the sign-in's
474
592
  if not _is_browser_error(exc):
475
593
  logger.warning("PaperSearch Pro's school sign-in failed: %s", type(exc).__name__)
476
594
  outcome = "failed"
@@ -478,14 +596,52 @@ class LoginMixin:
478
596
  if outcome == "rejected":
479
597
  school_login.turn_off(entity_id, "rejected")
480
598
  result._sign_in_note = SIGN_IN_REFUSED
599
+ elif outcome == "failed":
600
+ result._sign_in_note = SIGN_IN_NO_REPLY
601
+ elif outcome == "no_form":
602
+ result._sign_in_note = SIGN_IN_NO_FORM
603
+ elif outcome == "unsafe_form":
604
+ result._sign_in_note = SIGN_IN_UNCLEAR
481
605
  elif outcome == "submitted":
482
606
  # A step only the user can take may follow (a WeChat scan, a code: a new account, or one
483
607
  # not used for long; user, 2026-11-19): the wait goes on, its reminder saying so.
484
608
  result._sign_in_note = SIGN_IN_SECOND_STEP
485
609
  elif outcome == "needs_user":
486
- result._sign_in_note = SIGN_IN_ASKS.get(str(attempt.asks or ""), SIGN_IN_FOR_THE_USER)
610
+ result._sign_in_note = (school_login.entry_notice(attempt.blocked_entry) if attempt.blocked_entry
611
+ else SIGN_IN_ASKS.get(str(attempt.asks or ""), SIGN_IN_FOR_THE_USER))
612
+ if attempt.blocked_entry:
613
+ result._school_page_blocked = attempt.asks
614
+ if continuation is not None:
615
+ continuation.observe(page, allowed, tried=True, blocked=attempt.blocked_entry)
487
616
  return outcome == "submitted"
488
617
 
618
+ def _choose_way(self, page: Any, result: DownloadResult, school: str):
619
+ """Pro's ``attempt.choose_way``: the ways a sign-in chooser offers, picked from in the progress window, which
620
+ opens on them (user, 2026-11-29); within the school login's own time. The pick's index, -1 once the chooser
621
+ is gone (the user pressed a way in the browser), None when none was picked in time. 跳过本篇 and 终止 on the
622
+ card end the paper or the batch as anywhere else (_check_user_decision)."""
623
+ def choose(names: list[str], still: Any) -> int | None:
624
+ from .. import entitlements
625
+
626
+ key = f"choose-way:{id(self)}:{result.doi}"
627
+ since, deadline = time.time(), self._school_login_deadline(result)
628
+ progress_reporter.set_attention(key, f"选择 {school} 的登录方式" if school else "选择登录方式",
629
+ current=result.doi, phase="机构登录", deadline=deadline,
630
+ ways=names, school=school)
631
+ try:
632
+ while time.time() < deadline:
633
+ picked = entitlements.take_way(result.doi, since)
634
+ if picked is not None:
635
+ return picked
636
+ self._check_user_decision(result, page)
637
+ if not still():
638
+ return -1
639
+ time.sleep(POLL_MS / 1000)
640
+ return None
641
+ finally:
642
+ progress_reporter.clear_attention(key)
643
+ return choose
644
+
489
645
  def _school_sign_in_survey(self, page: Any, result: DownloadResult) -> bool:
490
646
  """A maintainer's survey of a school's sign-in page without its account (school_login.SURVEY_ENV):
491
647
  what Pro finds on the school's page, recorded once a paper; never the user's account. "press"
@@ -499,12 +655,13 @@ class LoginMixin:
499
655
  if self._login_wait_page(page) != "school_login":
500
656
  return False
501
657
  result._sign_in_surveyed = result._survey_finished = True
502
- also = school_login.pro_login_hosts(pro, str(self.config.get("idp_entity_id") or "").strip())
503
- if not school_login.may_fill(url, self.config, also):
658
+ also = school_login.pro_login_hosts(pro, str(self.config.get("idp_entity_id") or "").strip()) + tuple(sorted(getattr(self, "_shared_from_school", ()) or ()))
659
+ plain = school_login.pro_plain_hosts(pro, str(self.config.get("idp_entity_id") or "").strip())
660
+ if not school_login.may_fill(url, self.config, also, plain):
504
661
  self._event(result, "school_sign_in_survey", f"not the school's page: {urlparse(url).scheme}://{urlparse(url).hostname or ''}")
505
662
  return False
506
663
  try:
507
- said = str(pro.survey(page, lambda address: school_login.may_fill(address, self.config, also),
664
+ said = str(pro.survey(page, lambda address: school_login.may_fill(address, self.config, also, plain),
508
665
  press=os.environ.get(school_login.SURVEY_ENV) == "press",
509
666
  school=str(self.config.get("idp_entity_id") or "").strip()))
510
667
  except Exception as exc:
@@ -557,12 +714,19 @@ class LoginMixin:
557
714
  if not entry_opened and self.profile.generic and self._may_offer_entry(page):
558
715
  # A site without rules of its own: the shared rules found no way to the
559
716
  # school's login on its page, and there is nothing for the user to do here.
560
- result.reason = GENERIC_ENTRY_MISSING
717
+ # A page whose only sign-in is the site's own account (a password field, no sign
718
+ # of a school route) has no school login: mathnet.ru's Sbornik: Mathematics, only
719
+ # "Personal entry: Login, Password", ended as 暂未适配 (Windows, 2026-11-25). Not in
720
+ # the login after a failed PDF, whose ending is the PDF's.
721
+ personal = "" if getattr(result, "_pdf_retry_login", False) else self._personal_sign_in_only(page, result)
722
+ result.reason = NO_INSTITUTION_ENTRY if personal else GENERIC_ENTRY_MISSING
561
723
  looked_for, controls = self._entry_lookup_evidence(page)
724
+ if personal:
725
+ self._event(result, NO_INSTITUTION_ENTRY, personal)
562
726
  self._event(result, "login_entry_missing", looked_for)
563
727
  self._event(result, "login_entry_controls", controls)
564
- self._snapshot(page, result, "login entry missing")
565
- self._remember_no_entry(page, result, GENERIC_ENTRY_MISSING)
728
+ self._snapshot(page, result, "personal account sign-in only" if personal else "login entry missing")
729
+ self._remember_no_entry(page, result, result.reason)
566
730
  return False
567
731
  if (manual_selection and self.adapter.requires_institution_entry and not entry_opened
568
732
  and not self._is_human_login_page(page)):
@@ -578,12 +742,18 @@ class LoginMixin:
578
742
  self._event(result, "login_entry_missing",
579
743
  f"{str(page.url)[:160]} | no institution entry, access menu entry or institution sign-in link")
580
744
  self._snapshot(page, result, "login entry missing")
745
+ self._no_login_off_publisher(page, result)
581
746
  return False
582
747
  settle(page, 5_000)
583
748
  self._dismiss_cookie_banners(page, result)
584
749
  if self._click_openathens_entry(page, result):
585
750
  settle(page, 2_000)
586
- self._select_institution(page, result)
751
+ if not (self._on_login_site(page, result) and self._article_access_available(page)):
752
+ # On the login site's article, already given to the reader, there is no school to
753
+ # choose: the wait's first pass ends there. ScienceDirect's open article for
754
+ # jacc.org was taken as a page to choose the school on (institution_selection_required,
755
+ # then a page wait), Windows 2026-11-23.
756
+ self._select_institution(page, result)
587
757
  if not entry_opened and self._no_school_route(page, result, sites_opened):
588
758
  return False
589
759
 
@@ -597,6 +767,7 @@ class LoginMixin:
597
767
  outside_since = time.time() # last seen on the user's own login step
598
768
  article_returns = 0
599
769
  session_returns = 0
770
+ no_entry_since = 0.0 # since when the page has stood as the article's own, nothing to open on it
600
771
  away_from_publisher = False # on an IdP, federation or chooser page since the last probe
601
772
  returned = False # back on the publisher's site after such a page: try the PDF
602
773
  last_probe = time.time()
@@ -628,6 +799,15 @@ class LoginMixin:
628
799
  f"{self._login_wait_page(page)} after {self.page_wait_sec:.0f} s")
629
800
  self._wait_ran_out(result)
630
801
  return False
802
+ if not entry_opened and self._article_without_entry(page, result, sites_opened):
803
+ # Looked for again on every pass below (an entry drawn late): none for ENTRY_LOOK_SEC, the
804
+ # login has nothing to wait for (_end_without_entry), not the whole page wait.
805
+ no_entry_since = no_entry_since or time.time()
806
+ if time.time() - no_entry_since >= self.ENTRY_LOOK_SEC:
807
+ self._end_without_entry(page, result)
808
+ return False
809
+ else:
810
+ no_entry_since = 0.0
631
811
  # Navigation and auto-submit can finish during the preceding
632
812
  # wait. Never publish the classification of the old document.
633
813
  user_step = self._users_login_step(page)
@@ -653,7 +833,8 @@ class LoginMixin:
653
833
  step_since = (step_since or time.time()) if user_step else 0.0
654
834
  message = ""
655
835
  if user_step and (time.time() - step_since >= self.LOGIN_PROMPT_GRACE_SEC
656
- or getattr(result, "_login_attention", "")):
836
+ or getattr(result, "_login_attention", "")
837
+ or getattr(result, "_school_page_blocked", "")):
657
838
  kind = self._login_wait_page(page)
658
839
  message = ("请在浏览器窗口选择学校并完成机构登录" if kind in {"school_choice", "institution_chooser"}
659
840
  else getattr(result, "_sign_in_note", "") or "请在浏览器窗口完成机构登录")
@@ -672,6 +853,13 @@ class LoginMixin:
672
853
  if getattr(result, "_visited_idp", False):
673
854
  result._login_round_trip = True
674
855
  self._event(result, "login_round_trip_returned", here.geturl()[:160])
856
+ if getattr(result, "_route_round_trip", False):
857
+ # Back from the school's side by the login's route, unseen by this wait (_note_route_hop): the
858
+ # next try of the PDF is the one after the login, as when the wait saw it come back, and a page
859
+ # other than the article has the article opened again below. ACS (10.1021/jacs.6c10351, Windows
860
+ # 2026-11-26): the school's sign-in kept from the paper before, the login came back to its home
861
+ # page, taken for one to choose the school on until the page wait ran out (login_not_reached).
862
+ result._route_round_trip, returned, visited_idp = False, True, True
675
863
  if (on_publisher and self._is_success_article_url(here.geturl())
676
864
  and not self._is_auth_page(here.geturl()) and not self._challenge_shell(page)
677
865
  and (returned or time.time() - last_probe >= self.WAIT_PROBE_EVERY_SEC)
@@ -704,6 +892,14 @@ class LoginMixin:
704
892
  # 2026-11-17), and the page read before it is read again.
705
893
  result._login_round_trip = True
706
894
  return True
895
+ if self._at_login_landing(here.geturl(), result):
896
+ # From the login landing the login went round as well, though the article
897
+ # is still offered or denied: the next pass tries the PDF and, with the
898
+ # page's evidence, ends the wait as not subscribed. NEJM Catalyst
899
+ # (10.1056/cat.25.0121, Windows 2026-11-23): the school's sign-in kept from
900
+ # the paper before, authenticateSharedSP, "Get Access" again; the wait ran
901
+ # out on the article (login_not_reached).
902
+ result._login_round_trip = returned = True
707
903
  except Exception as exc:
708
904
  self._event(result, "idp_return_article_error", type(exc).__name__)
709
905
  continue
@@ -1342,6 +1538,15 @@ class LoginMixin:
1342
1538
  self._event(result, "login_page_opened", target)
1343
1539
  return True
1344
1540
 
1541
+ @staticmethod
1542
+ def _on_login_site(page: Any, result: DownloadResult | None) -> bool:
1543
+ """The page is on the site the adapter sent this item's login to
1544
+ (``_open_adapter_login_page``: ScienceDirect's same article for an Elsevier
1545
+ journal's own site), not on the site the login came from."""
1546
+ source = str(getattr(result, "_login_site_from", "") or "") if result is not None else ""
1547
+ host = (urlparse(str(getattr(page, "url", "") or "")).hostname or "").lower()
1548
+ return bool(source and host and host != (urlparse(source).hostname or "").lower())
1549
+
1345
1550
  def _return_from_login_site(self, page: Any, result: DownloadResult) -> bool:
1346
1551
  """The adapter sent the login to another site (an Elsevier journal site's
1347
1552
  institution login is ScienceDirect's). Once that site shows the institution
@@ -1349,12 +1554,22 @@ class LoginMixin:
1349
1554
  2026-10-31), open the article again on the journal's own site: whether the school
1350
1555
  has access, and which PDF to take, is that site's to answer. If the journal
1351
1556
  site still gives only the abstract, go back once to the login site's
1352
- article, which then decides as before. True when navigated."""
1557
+ article, which then decides as before. True when navigated.
1558
+
1559
+ Not in the login after a failed PDF: the journal's site has refused that PDF
1560
+ already, and the login site's article decides. Giving the article, its PDF is
1561
+ taken there (``_article_access_available``); denying it to the school's session,
1562
+ the school has no access (``_login_block_reason``). jacc.org
1563
+ (10.1016/j.jcmg.2025.09.021, Windows 2026-11-23): "This is an Open Access Article"
1564
+ by "GET ACCESS", its PDF 403; ScienceDirect's same article showed "Open access" and
1565
+ its full text, and the login waited a page wait there and ended as pdf_not_captured."""
1353
1566
  url = str(getattr(page, "url", "") or "")
1354
1567
  host = (urlparse(url).hostname or "").lower()
1355
1568
  source = getattr(result, "_login_site_from", "")
1356
1569
  fallback = getattr(result, "_login_site_fallback", "")
1357
1570
  if source and host != (urlparse(source).hostname or "").lower():
1571
+ if getattr(result, "_pdf_retry_login", False):
1572
+ return False
1358
1573
  if not (self._has_publisher_institution_session(page) or self._article_access_available(page)):
1359
1574
  return False
1360
1575
  result._login_site_from, result._login_site_fallback = "", url
@@ -1479,6 +1694,29 @@ class LoginMixin:
1479
1694
  return null;
1480
1695
  }"""
1481
1696
 
1697
+ # In an opened access menu only: its "Check Access" when the panel around it says the access is an
1698
+ # institution's. APA PsycNET's "Get Access" panel: "You may have access to this content with your personal
1699
+ # login credentials or through your institutional subscription. CHECK ACCESS", which opens its sign-in page
1700
+ # with the institutions' list (select#entityID); no entry was found there (2026-11-24). Elsewhere "Check
1701
+ # Access" is an offer (access_rules.OFFER_LABEL).
1702
+ _MENU_CHECK_ACCESS_JS = r"""() => {
1703
+ const shown = el => el.getClientRects().length > 0 && getComputedStyle(el).visibility !== 'hidden';
1704
+ const controls = [...document.querySelectorAll('a, button, [role="button"]')];
1705
+ for (const [index, el] of controls.entries()) {
1706
+ const label = (el.innerText || el.getAttribute('aria-label') || '').replace(/\s+/g, ' ').trim();
1707
+ if (!shown(el) || !/^check access$/i.test(label)) continue;
1708
+ for (let panel = el.parentElement, n = 0; panel && panel !== document.body && n < 6; panel = panel.parentElement, n++) {
1709
+ const text = (panel.innerText || '').replace(/\s+/g, ' ');
1710
+ if (text.length > 1500) break;
1711
+ if (/\binstitution(?:al)?\b/i.test(text)) {
1712
+ const href = el.tagName === 'A' && el.href && !/^javascript:/i.test(el.href) ? el.href : '';
1713
+ return {label: label.slice(0, 120), href, index};
1714
+ }
1715
+ }
1716
+ }
1717
+ return null;
1718
+ }"""
1719
+
1482
1720
  def _open_entry_from_access_menu(self, page: Any, result: DownloadResult | None) -> bool:
1483
1721
  """Open the site's access menu once per page and take the institution entry
1484
1722
  inside it: the adapter's own rule, else ``_INSTITUTION_ENTRY_JS``. An
@@ -1495,10 +1733,11 @@ class LoginMixin:
1495
1733
  result._access_menus = tried | {url} # opened once: a second click would close it
1496
1734
  self._event(result, "access_menu_opened", str(label)[:120])
1497
1735
  entry = None
1498
- if pump_until(page, lambda: bool(page.evaluate(self._INSTITUTION_ENTRY_JS)), 2_500):
1736
+ if pump_until(page, lambda: bool(page.evaluate(self._INSTITUTION_ENTRY_JS)
1737
+ or page.evaluate(self._MENU_CHECK_ACCESS_JS)), 2_500):
1499
1738
  if self.adapter.open_institution_entry(page, result):
1500
1739
  return True
1501
- entry = page.evaluate(self._INSTITUTION_ENTRY_JS)
1740
+ entry = page.evaluate(self._INSTITUTION_ENTRY_JS) or page.evaluate(self._MENU_CHECK_ACCESS_JS)
1502
1741
  if not isinstance(entry, dict):
1503
1742
  return False
1504
1743
  href = str(entry.get("href") or "")
@@ -1547,6 +1786,8 @@ class LoginMixin:
1547
1786
  "button:has-text('Institutional Access')",
1548
1787
  "a:has-text('Institutional Access')",
1549
1788
  "button:has-text('Institutional Sign In')",
1789
+ "a:has-text('Change institution')",
1790
+ "button:has-text('Change institution')",
1550
1791
  )
1551
1792
  sso_selectors = (*self.adapter.sso_selectors, *sso_selectors)
1552
1793
  for selector in sso_selectors:
@@ -1600,7 +1841,8 @@ class LoginMixin:
1600
1841
  'log in via your institution',
1601
1842
  'provided by your institution',
1602
1843
  'username/password provided by your institution',
1603
- 'log in with username/password provided by your institution'
1844
+ 'log in with username/password provided by your institution',
1845
+ 'change institution'
1604
1846
  ];
1605
1847
  const clickableSelector = 'a,button,[role="button"],input[type="button"],input[type="submit"]';
1606
1848
  const textOf = (el) => [
@@ -1663,7 +1905,7 @@ class LoginMixin:
1663
1905
  """A page of the publisher's own where its institution entry would be: not
1664
1906
  a login, IdP or chooser page, no verification, no school login form."""
1665
1907
  url = str(getattr(page, "url", "") or "")
1666
- return (url.startswith("http") and self._on_publisher_host(url) and not self._is_auth_page(url)
1908
+ return (url.startswith("http") and self._on_landing_site(url) and not self._is_auth_page(url)
1667
1909
  and not self._challenge_shell(page) and not self._is_human_login_page(page))
1668
1910
 
1669
1911
  # The page's own sign-in and access controls, for the record of a missing entry.
@@ -1867,6 +2109,69 @@ class LoginMixin:
1867
2109
  self._remember_no_entry(page, result, NO_INSTITUTION_ENTRY)
1868
2110
  return True
1869
2111
 
2112
+ def _no_login_off_publisher(self, page: Any, result: DownloadResult) -> None:
2113
+ """The login after a failed PDF found no institution entry on a site its publisher's rules do not
2114
+ name and the page shows no sign of a school route (``_route_probe``): the reason is the site's
2115
+ (``NO_INSTITUTION_ENTRY``), kept for the batch, not the PDF's. The PDF was looked for by the
2116
+ publisher's rules, on its own site, which says nothing of this one: Springer Nature's DOIs that
2117
+ open springermedizin.de, springerprofessional.de or scientificamerican.com (the PDF address 404,
2118
+ no school login) ended as 原因不明 · 没取到 PDF, the next paper of the same site as 网站不提供学校登录
2119
+ (Windows 2026-11-24). On the publisher's own site the PDF's reason stays: its rules may be at fault."""
2120
+ url = str(getattr(page, "url", "") or "")
2121
+ if (not url.startswith("http") or self.profile.generic or self._on_publisher_host(url)
2122
+ or not self._on_landing_site(url) or self._is_auth_page(url) or self._school_login_done()):
2123
+ return
2124
+ probe = self._route_probe(page)
2125
+ if probe is None or probe["signs"]:
2126
+ return
2127
+ result.reason = NO_INSTITUTION_ENTRY
2128
+ self._event(result, NO_INSTITUTION_ENTRY,
2129
+ f"{url[:160]} | a site the publisher's rules do not name: no PDF, no school login entry")
2130
+ self._remember_no_entry(page, result, NO_INSTITUTION_ENTRY)
2131
+
2132
+ # The controls a school is searched for in, on a publisher's page (the CARSI-mode entry's own check).
2133
+ _INSTITUTION_SEARCH_BOX = ('input[name*="institution" i]:visible, input[placeholder*="institution" i]:visible, '
2134
+ 'input[name*="school" i]:visible, input[placeholder*="school" i]:visible')
2135
+
2136
+ # How long the article's own page may stand with no entry opened on it and nothing chosen before the
2137
+ # login ends (``_end_without_entry``): the entry is looked for again on every pass of the wait meanwhile
2138
+ # (one drawn late, ScienceDirect's after linkinghub), and the PDF tried once (WAIT_PROBE_EVERY_SEC).
2139
+ ENTRY_LOOK_SEC = 20
2140
+
2141
+ def _article_without_entry(self, page: Any, result: DownloadResult, sites_opened: int) -> bool:
2142
+ """The page is still the article's own on the publisher's site, no login page was opened, no school
2143
+ chosen or reached, and it shows no chooser, no institution search box and nobody typing: nothing for
2144
+ a school's login there. Not a redirect, a login, chooser or verification page."""
2145
+ url = str(getattr(page, "url", "") or "")
2146
+ if (sum(e["state"] == "login_page_opened" for e in result.events) > sites_opened
2147
+ or getattr(result, "_institution_not_listed", False)
2148
+ or any(e["state"] in self._SCHOOL_CHOSEN for e in result.events) or self._school_login_done()
2149
+ or not url.startswith("http") or self.adapter.is_redirect_page(url) or self._is_auth_page(url)
2150
+ or not self._on_landing_site(url) or not self._is_success_article_url(url)
2151
+ or self._is_human_login_page(page) or self._challenge_shell(page)):
2152
+ return False
2153
+ try:
2154
+ searching = page.locator(self._INSTITUTION_SEARCH_BOX).count()
2155
+ except Exception as exc:
2156
+ if not _is_browser_error(exc):
2157
+ raise
2158
+ return False
2159
+ return not ((isinstance(searching, int) and searching > 0) or self._has_visible_editable_input(page)
2160
+ or self.adapter.institution_chooser_open(page))
2161
+
2162
+ def _end_without_entry(self, page: Any, result: DownloadResult) -> None:
2163
+ """The login ends on the article's own page that stood ``ENTRY_LOOK_SEC`` with no entry the rules
2164
+ could open (``_article_without_entry``): ``publisher_institution_entry_missing``, PaperSearch's to fix.
2165
+ nature.com's Nature Cities (Windows 2026-11-24) stood the whole page wait on its article, its entry
2166
+ not one the rules knew, then 原因不明 · 没进入学校登录页."""
2167
+ url = str(getattr(page, "url", "") or "")
2168
+ result.reason = "publisher_institution_entry_missing"
2169
+ looked_for, controls = self._entry_lookup_evidence(page)
2170
+ self._event(result, "login_entry_missing",
2171
+ f"{url[:160]} | no entry opened on the article's page in {self.ENTRY_LOOK_SEC} s; {looked_for}")
2172
+ self._event(result, "login_entry_controls", controls)
2173
+ self._snapshot(page, result, "login entry missing")
2174
+
1870
2175
  # The publisher's own account sign-in, with no school entry on it, is never the school's
1871
2176
  # login: the wait ends once it has stood this long (time for an institutional option
1872
2177
  # drawn late by script to show).
@@ -1884,7 +2189,7 @@ class LoginMixin:
1884
2189
  typing. A form the user fills stays theirs."""
1885
2190
  url = str(getattr(page, "url", "") or "")
1886
2191
  parsed = urlparse(url)
1887
- if (parsed.scheme not in ("http", "https") or not self._on_publisher_host(url)
2192
+ if (parsed.scheme not in ("http", "https") or not self._on_landing_site(url)
1888
2193
  or self._is_idp_host(parsed.netloc) or self._on_school_login_page(url)
1889
2194
  or self._is_federation_chooser(url) or self._school_login_done()
1890
2195
  or (result is not None and any(e.get("state") in self._SCHOOL_CHOSEN for e in result.events))):
@@ -1933,7 +2238,10 @@ class LoginMixin:
1933
2238
  """An earlier paper of this batch found no school login entry on this site's page
1934
2239
  (``login_routes.no_entry_since``) and this page shows none either: ended at once,
1935
2240
  nothing looked for or clicked, with that paper's reason. The login after a failed PDF
1936
- ends as the first paper's did, the PDF's reason kept."""
2241
+ ends as it does on the page itself (``_complete_login_steps``): on a site without rules
2242
+ the shared rules found no entry (``GENERIC_ENTRY_MISSING``), elsewhere the PDF's reason
2243
+ is kept. jle.com (10.1684/ndt.2025.156, Windows 2026-11-23): the first paper ended so,
2244
+ the second, its PDF 403 "Accès refusé", as pdf_not_captured, tried again at the end."""
1937
2245
  from .. import login_routes, progress_reporter
1938
2246
 
1939
2247
  host = (urlparse(str(getattr(page, "url", "") or "")).hostname or "").lower()
@@ -1951,6 +2259,13 @@ class LoginMixin:
1951
2259
  f"none on this page either")
1952
2260
  if not getattr(result, "_pdf_retry_login", False):
1953
2261
  result.reason = reason
2262
+ elif self.profile.generic:
2263
+ result.reason = GENERIC_ENTRY_MISSING
2264
+ elif not self._on_publisher_host(str(getattr(page, "url", "") or "")):
2265
+ # A site its publisher's rules do not name: the PDF was looked for by those rules, on the publisher's own
2266
+ # site, which says nothing of this one; the reason is the site's (Scientific American in Springer Nature's
2267
+ # list, Windows 2026-11-24: nature.com's address 404, then 原因不明 · 没取到 PDF).
2268
+ result.reason = reason
1954
2269
  return True
1955
2270
 
1956
2271
  def _remember_no_entry(self, page: Any, result: DownloadResult, reason: str) -> None:
@@ -1977,11 +2292,15 @@ class LoginMixin:
1977
2292
  ("/institutionlogin", "/idp/", "/entity/"))
1978
2293
 
1979
2294
  # The labels of an institution entry, the whole label in lower case (CARSI mode).
2295
+ # "Change institution": a site that knows the reader's institution and denies the article to it
2296
+ # (nature.com's "Access to this article via <consortium> is not available", Nature Cities, Windows
2297
+ # 2026-11-24) opens its chooser from there; the school's own login then tells whether the school has it.
1980
2298
  _INSTITUTION_ENTRY_LABELS = frozenset({
1981
2299
  "access through your institution", "access through institution",
1982
2300
  "access through your organization", "institutional access",
1983
2301
  "institutional login", "institutional sign in", "log in via an institution",
1984
2302
  "log in through your institution", "log in via your institution", "log in via institution",
2303
+ "change institution",
1985
2304
  })
1986
2305
 
1987
2306
  def _click_manual_institution_entry(self, page: Any, result: DownloadResult | None) -> bool:
@@ -2003,19 +2322,41 @@ class LoginMixin:
2003
2322
  if control.evaluate("el => el.tagName !== 'A' && Boolean(el.form || el.closest('form'))"):
2004
2323
  continue
2005
2324
  href = control.get_attribute("href", timeout=2_000) or control.get_attribute("formaction", timeout=2_000) or ""
2325
+ # A link whose address only the site's script follows (ASCO's
2326
+ # <a data-href="/action/ssostart">, 2026-11-25).
2327
+ scripted = "" if href else (control.get_attribute("data-href", timeout=2_000) or "")
2006
2328
  except Exception as exc:
2007
2329
  if not _is_browser_error(exc):
2008
2330
  raise
2009
2331
  continue # gone or changed while the page moved on (JAMA Pediatrics, 2026-11-02)
2010
2332
  if href and not self._manual_institution_target_allowed(urljoin(str(page.url), href)):
2011
2333
  continue
2334
+ before = str(getattr(page, "url", "") or "")
2012
2335
  if not self._click_control(page, control, result, f"institution entry: {label.strip()[:80]}"):
2013
2336
  continue # nothing was clicked (script_click_failed)
2014
2337
  if result is not None:
2015
2338
  self._event(result, "sso_entry_clicked", "generic-institution-chooser")
2339
+ if scripted:
2340
+ self._follow_scripted_entry(page, result, before, urljoin(before, scripted))
2016
2341
  return True
2017
2342
  return False
2018
2343
 
2344
+ # How long a clicked entry whose address only the site's script follows may leave the page on its own.
2345
+ SCRIPTED_ENTRY_WAIT_MS = 5_000
2346
+
2347
+ def _follow_scripted_entry(self, page: Any, result: DownloadResult | None, before: str, target: str) -> None:
2348
+ """The entry's own address opened when its click left the page where it was:
2349
+ ASCO's "INSTITUTIONAL LOGIN" (``data-href="/action/ssostart"``) answered a
2350
+ click that timed out, then the script's click, only now and then; the other
2351
+ times the login wait ran its minute on the article page (2026-11-25). Only
2352
+ an address the chooser may open (``_manual_institution_target_allowed``)."""
2353
+ pump_until(page, lambda: str(getattr(page, "url", "") or "") != before, self.SCRIPTED_ENTRY_WAIT_MS)
2354
+ if str(getattr(page, "url", "") or "") != before or not self._manual_institution_target_allowed(target):
2355
+ return
2356
+ open_page(page, target, timeout_ms=30_000)
2357
+ if result is not None:
2358
+ self._event(result, "sso_entry_opened", f"the entry's own address: {urlparse(target).path[:80]}")
2359
+
2019
2360
  def _has_visible_editable_input(self, page: Any) -> bool:
2020
2361
  """Someone may be typing here: a visible editable field holds a value. Read
2021
2362
  on every pass of the login wait; a page navigating meanwhile ("Execution
@@ -2069,6 +2410,27 @@ class LoginMixin:
2069
2410
  return True
2070
2411
  return self.adapter.is_article_page_url(url) is True
2071
2412
 
2413
+ def _on_landing_site(self, url: str) -> bool:
2414
+ """The publisher's own site (``_on_publisher_host``), or the site this paper's article opened on
2415
+ past its DOI's redirects (``_note_article_host``), which no profile may name: Nature Digest's
2416
+ natureasia.com in Springer Nature's list, whose personal subscribers' sign-in was taken for the
2417
+ school's login page and held the publisher's 73 other papers, again after each 登录并继续
2418
+ (Windows, 2026-11-24)."""
2419
+ host = (urlparse(url).hostname or "").lower()
2420
+ return self._on_publisher_host(url) or bool(host) and host == getattr(self, "_article_host", "")
2421
+
2422
+ def _note_article_host(self, page: Any) -> None:
2423
+ """The site the article opened on (``_on_landing_site``): not one on the school's side, a
2424
+ login, chooser or federation page, nor one this paper's login has gone on to."""
2425
+ url = str(getattr(page, "url", "") or "")
2426
+ parsed = urlparse(url)
2427
+ host = (parsed.hostname or "").lower()
2428
+ if (parsed.scheme not in ("http", "https") or not host or getattr(self, "_route_away", False)
2429
+ or self._is_idp_host(host) or self._on_school_login_page(url) or self._is_auth_page(url)
2430
+ or self._is_federation_chooser(url) or self._school_login_done()):
2431
+ return
2432
+ self._article_host = host
2433
+
2072
2434
  def _page_wait_over(self, page: Any, outside_since: float) -> tuple[bool, float]:
2073
2435
  """Whether a login wait has been off the user's own login step for a whole
2074
2436
  page wait, and when that step was last seen (now, when on it)."""
@@ -2155,7 +2517,7 @@ class LoginMixin:
2155
2517
  return "authentication_redirect"
2156
2518
  if self._is_auth_page(url):
2157
2519
  return "institution_chooser" if self.institution_query else "school_choice"
2158
- return "publisher" if self._on_publisher_host(url) else "other"
2520
+ return "publisher" if self._on_landing_site(url) else "other"
2159
2521
 
2160
2522
  def _is_human_login_page(self, page: Any) -> bool:
2161
2523
  url = str(getattr(page, "url", "") or "")