papersearch 0.4.10 → 0.4.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.en.md +128 -226
- package/README.md +128 -226
- package/assets/carsi-flow.en.png +0 -0
- package/assets/carsi-flow.png +0 -0
- package/assets/overview.en.png +0 -0
- package/assets/overview.png +0 -0
- package/carsi/README.md +1 -1
- package/carsi/paper_search_carsi/adapters/ams/__init__.py +12 -0
- package/carsi/paper_search_carsi/adapters/elsevier/__init__.py +5 -2
- package/carsi/paper_search_carsi/adapters/elsevier/sciencedirect.py +18 -1
- package/carsi/paper_search_carsi/adapters/iop/__init__.py +19 -4
- package/carsi/paper_search_carsi/adapters/platforms/atypon/__init__.py +24 -14
- package/carsi/paper_search_carsi/adapters/platforms/silverchair/__init__.py +23 -0
- package/carsi/paper_search_carsi/assets/capsule.html +36 -9
- package/carsi/paper_search_carsi/browser/preview.py +16 -3
- package/carsi/paper_search_carsi/browser/watchdog.py +68 -4
- package/carsi/paper_search_carsi/capsule_placement.py +51 -31
- package/carsi/paper_search_carsi/download_diagnostics.py +3 -1
- package/carsi/paper_search_carsi/engine/access_rules.py +11 -0
- package/carsi/paper_search_carsi/engine/batch.py +21 -3
- package/carsi/paper_search_carsi/engine/batch_access.py +3 -0
- package/carsi/paper_search_carsi/engine/batch_capture.py +61 -11
- package/carsi/paper_search_carsi/engine/batch_common.py +4 -0
- package/carsi/paper_search_carsi/engine/batch_diagnostics.py +3 -0
- package/carsi/paper_search_carsi/engine/batch_institution.py +59 -40
- package/carsi/paper_search_carsi/engine/batch_login.py +121 -16
- package/carsi/paper_search_carsi/engine/bridge.py +5 -2
- package/carsi/paper_search_carsi/engine/supplements.py +66 -4
- package/carsi/paper_search_carsi/progress_capsule.py +93 -11
- package/carsi/paper_search_carsi/progress_macos.py +35 -10
- package/carsi/paper_search_carsi/progress_reporter.py +42 -18
- package/carsi/paper_search_carsi/progress_view.py +35 -13
- package/carsi/paper_search_carsi/server.py +7 -1
- package/dist/capabilities/journal-metrics/JournalMetricsService.d.ts.map +1 -1
- package/dist/capabilities/journal-metrics/JournalMetricsService.js +2 -1
- package/dist/capabilities/journal-metrics/JournalMetricsService.js.map +1 -1
- package/dist/capabilities/pdf-discovery/batch.d.ts +2 -0
- package/dist/capabilities/pdf-discovery/batch.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/batch.js +45 -10
- package/dist/capabilities/pdf-discovery/batch.js.map +1 -1
- package/dist/capabilities/pdf-discovery/batchSummary.d.ts +7 -1
- package/dist/capabilities/pdf-discovery/batchSummary.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/batchSummary.js +24 -0
- package/dist/capabilities/pdf-discovery/batchSummary.js.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiAttempt.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiAttempt.js +6 -0
- package/dist/capabilities/pdf-discovery/carsi/CarsiAttempt.js.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiMcpClient.d.ts +3 -0
- package/dist/capabilities/pdf-discovery/carsi/CarsiMcpClient.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiMcpClient.js +29 -4
- package/dist/capabilities/pdf-discovery/carsi/CarsiMcpClient.js.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiReadiness.d.ts +2 -0
- package/dist/capabilities/pdf-discovery/carsi/CarsiReadiness.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiReadiness.js +2 -0
- package/dist/capabilities/pdf-discovery/carsi/CarsiReadiness.js.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/types.d.ts +12 -0
- package/dist/capabilities/pdf-discovery/carsi/types.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/tiers/publisherApi.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/tiers/publisherApi.js +2 -1
- package/dist/capabilities/pdf-discovery/tiers/publisherApi.js.map +1 -1
- package/dist/cli.js +19 -8
- package/dist/cli.js.map +1 -1
- package/dist/config/ConfigService.d.ts.map +1 -1
- package/dist/config/ConfigService.js +28 -2
- package/dist/config/ConfigService.js.map +1 -1
- package/dist/config/apiKeySignup.d.ts +13 -0
- package/dist/config/apiKeySignup.d.ts.map +1 -0
- package/dist/config/apiKeySignup.js +32 -0
- package/dist/config/apiKeySignup.js.map +1 -0
- package/dist/infrastructure/runlog/failureClass.d.ts.map +1 -1
- package/dist/infrastructure/runlog/failureClass.js +6 -0
- package/dist/infrastructure/runlog/failureClass.js.map +1 -1
- package/dist/management/capability-profile/index.d.ts +7 -0
- package/dist/management/capability-profile/index.d.ts.map +1 -1
- package/dist/management/capability-profile/index.js +7 -0
- package/dist/management/capability-profile/index.js.map +1 -1
- package/dist/management/carsi/installer.js +5 -5
- package/dist/management/carsi/installer.js.map +1 -1
- package/dist/management/diagnostics/index.d.ts.map +1 -1
- package/dist/management/diagnostics/index.js +4 -1
- package/dist/management/diagnostics/index.js.map +1 -1
- package/dist/management/failures/exportReport.js +3 -3
- package/dist/management/reports/index.d.ts.map +1 -1
- package/dist/management/reports/index.js +6 -1
- package/dist/management/reports/index.js.map +1 -1
- package/dist/management/updates/index.d.ts +6 -1
- package/dist/management/updates/index.d.ts.map +1 -1
- package/dist/management/updates/index.js +18 -11
- package/dist/management/updates/index.js.map +1 -1
- package/dist/platforms/SemanticScholarSearcher.d.ts.map +1 -1
- package/dist/platforms/SemanticScholarSearcher.js +2 -1
- package/dist/platforms/SemanticScholarSearcher.js.map +1 -1
- package/package.json +2 -3
- package/skills/paper-search/SKILL.md +8 -14
- package/skills/paper-search/references/browser-download.md +7 -6
- package/skills/paper-search/references/capability-routing.md +3 -3
- package/skills/paper-search/references/carsi-setup.md +1 -1
- package/skills/paper-search/references/cli-contract.md +2 -2
- package/skills/paper-search/references/management-layer.md +1 -1
- package/skills/paper-search/references/publisher-support.md +6 -4
- package/skills/paper-search/references/troubleshooting.md +1 -2
- package/carsi/NOTICE +0 -5
|
@@ -150,7 +150,7 @@ class CaptureMixin:
|
|
|
150
150
|
getattr(self, "_fallback_pdf", None))
|
|
151
151
|
self._capture_doi = (doi or "").lower()
|
|
152
152
|
self._expected_title = self._citation_title(page) or getattr(self, "_record_title", "")
|
|
153
|
-
self._show_title()
|
|
153
|
+
self._show_title(page)
|
|
154
154
|
try:
|
|
155
155
|
try:
|
|
156
156
|
tabs = [tab for tab in list(page.context.pages) if not tab.is_closed()]
|
|
@@ -208,7 +208,7 @@ class CaptureMixin:
|
|
|
208
208
|
self._phase(result, "pdf")
|
|
209
209
|
self._capture_doi = (doi or "").lower()
|
|
210
210
|
self._expected_title = self._citation_title(page) or getattr(self, "_record_title", "")
|
|
211
|
-
self._show_title()
|
|
211
|
+
self._show_title(page)
|
|
212
212
|
self._fallback_pdf = None
|
|
213
213
|
tried_before = len(result.pdf_attempts)
|
|
214
214
|
try:
|
|
@@ -311,9 +311,22 @@ class CaptureMixin:
|
|
|
311
311
|
return ""
|
|
312
312
|
return " ".join(value.split()) if isinstance(value, str) else ""
|
|
313
313
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
title
|
|
314
|
+
@staticmethod
|
|
315
|
+
def _dublin_core_title(page: Any) -> str:
|
|
316
|
+
"""The article page's Dublin Core title (dc.Title), which Atypon sites such
|
|
317
|
+
as SIAM give without a citation_title (2026-11-08). For display only."""
|
|
318
|
+
try:
|
|
319
|
+
value = page.evaluate(
|
|
320
|
+
"() => (document.querySelector('meta[name=\"dc.title\" i]') || {}).content || ''")
|
|
321
|
+
except Exception:
|
|
322
|
+
return ""
|
|
323
|
+
return " ".join(value.split()) if isinstance(value, str) else ""
|
|
324
|
+
|
|
325
|
+
def _show_title(self, page: Any = None) -> None:
|
|
326
|
+
"""The article's title in the progress window, once its page names it: the
|
|
327
|
+
title the identity check uses, else the page's Dublin Core title (only shown,
|
|
328
|
+
never checked against: the capsule showed the DOI instead, 2026-11-08)."""
|
|
329
|
+
title = getattr(self, "_expected_title", "") or (self._dublin_core_title(page) if page is not None else "")
|
|
317
330
|
if not title or title == getattr(self, "_shown_title", ""):
|
|
318
331
|
return
|
|
319
332
|
self._shown_title = title
|
|
@@ -324,6 +337,25 @@ class CaptureMixin:
|
|
|
324
337
|
except Exception:
|
|
325
338
|
pass
|
|
326
339
|
|
|
340
|
+
# Figshare links: their files are found by its own API in the attachment step.
|
|
341
|
+
_FIGSHARE_LINKED_JS = "() => !!document.querySelector('a[href*=\"figshare.com\"]')"
|
|
342
|
+
|
|
343
|
+
def _remember_listed_supplements(self, page: Any, doi: str, result: DownloadResult) -> None:
|
|
344
|
+
"""The files the article page lists, read before the PDF takes its tab: the
|
|
345
|
+
attachment step then need not load the page again (AHA's page took more
|
|
346
|
+
than that step's 60 s once, 2026-11-08). Only from an adapter that reads
|
|
347
|
+
them without leaving the page, and not beside Figshare links."""
|
|
348
|
+
read = getattr(self.adapter, "listed_supplement_links", None)
|
|
349
|
+
if read is None or getattr(result, "_listed_supplements", None):
|
|
350
|
+
return
|
|
351
|
+
try:
|
|
352
|
+
links = read(page, doi)
|
|
353
|
+
if links and not page.evaluate(self._FIGSHARE_LINKED_JS):
|
|
354
|
+
result._listed_supplements = list(links)
|
|
355
|
+
except Exception as exc:
|
|
356
|
+
if not _is_browser_error(exc):
|
|
357
|
+
raise
|
|
358
|
+
|
|
327
359
|
def _capture_pdf_channels(self, page: Any, doi: str, result: DownloadResult) -> tuple[bytes | None, str, str | None]:
|
|
328
360
|
"""Capture the PDF for ``doi`` from ``page``.
|
|
329
361
|
|
|
@@ -332,8 +364,9 @@ class CaptureMixin:
|
|
|
332
364
|
was observed during capture, else ``None``.
|
|
333
365
|
"""
|
|
334
366
|
self._event(result, "pdf_capture_started")
|
|
367
|
+
self._remember_listed_supplements(page, doi, result)
|
|
335
368
|
captured: dict[str, Any] = {"bytes": None, "url": "", "deferred_url": "", "block_reason": None,
|
|
336
|
-
"suspect_block": None}
|
|
369
|
+
"suspect_block": None, "closed": False, "readers": set()}
|
|
337
370
|
cdp_session = None
|
|
338
371
|
native_redirects: dict[str, list[Any]] = {}
|
|
339
372
|
cdn_redirects: dict[str, list[Any]] = {}
|
|
@@ -387,7 +420,9 @@ class CaptureMixin:
|
|
|
387
420
|
url = event.get("request", {}).get("url", "")
|
|
388
421
|
response = SimpleNamespace(url=url, status=200, headers={}, history=history)
|
|
389
422
|
urls = self._response_urls(response)
|
|
390
|
-
|
|
423
|
+
# Kept by address too: Chrome can answer the final PDF under another
|
|
424
|
+
# request id. The bound PDF's own file on its CDN is one (RSC, 2026-11-07).
|
|
425
|
+
if ((self.adapter.is_pdf_cdn_url(url, doi) or self._bound_pdf_copy(url, response, doi, article_options))
|
|
391
426
|
and self._response_matches_article(response, doi, **article_options)):
|
|
392
427
|
cdn_redirects[url] = list(history)
|
|
393
428
|
if (any(hop in rejected_pdf_urls for hop in urls)
|
|
@@ -408,11 +443,16 @@ class CaptureMixin:
|
|
|
408
443
|
for header in event.get("responseHeaders", [])
|
|
409
444
|
}
|
|
410
445
|
url = event.get("request", {}).get("url", "")
|
|
446
|
+
history = native_redirects.get(event.get("networkId", ""), []) or cdn_redirects.get(url, [])
|
|
411
447
|
if (self.adapter.discards_unbound_pdfs
|
|
412
448
|
and "application/pdf" in headers.get("content-type", "").lower()
|
|
413
449
|
and (url in rejected_pdf_urls or self._is_supplementary_url(url)
|
|
414
450
|
or self._is_supplementary_url(headers.get("content-disposition", ""))
|
|
415
|
-
or not self._article_pdf_url_matches(url, doi, **article_options)
|
|
451
|
+
or not (self._article_pdf_url_matches(url, doi, **article_options)
|
|
452
|
+
# The bound PDF's own file on the host its address redirects
|
|
453
|
+
# to (RSC's article-pdf -> rscj.silverchair-cdn.com, 2026-11-07).
|
|
454
|
+
or self._bound_pdf_copy(url, SimpleNamespace(url=url, history=history),
|
|
455
|
+
doi, article_options)))):
|
|
416
456
|
rejected_pdf_urls.add(url)
|
|
417
457
|
return
|
|
418
458
|
if ("application/pdf" in headers.get("content-type", "").lower()
|
|
@@ -437,7 +477,6 @@ class CaptureMixin:
|
|
|
437
477
|
# response.body(). Apply the same article/attachment guards
|
|
438
478
|
# before reading the response through CDP instead.
|
|
439
479
|
if self._uses_article_pdf_validation():
|
|
440
|
-
history = native_redirects.get(event.get("networkId", ""), []) or cdn_redirects.get(url, [])
|
|
441
480
|
response = SimpleNamespace(
|
|
442
481
|
url=url, headers=headers,
|
|
443
482
|
status=event.get("responseStatusCode", 0), history=history,
|
|
@@ -496,6 +535,12 @@ class CaptureMixin:
|
|
|
496
535
|
self._event(result, "browser_response_continue_error", type(exc).__name__)
|
|
497
536
|
|
|
498
537
|
def on_response(response: Any) -> None:
|
|
538
|
+
# A response handled after this capture is over reads nothing: a body
|
|
539
|
+
# read that never returned there (after AIAA's blocked PDF) stopped the
|
|
540
|
+
# watchdog for the whole process, and the next article with it
|
|
541
|
+
# (Chicago, browser_unresponsive, 2026-11-07).
|
|
542
|
+
if captured["closed"]:
|
|
543
|
+
return
|
|
499
544
|
# The tab's own document answers, for the attempt's record.
|
|
500
545
|
try:
|
|
501
546
|
request = getattr(response, "request", None)
|
|
@@ -539,7 +584,8 @@ class CaptureMixin:
|
|
|
539
584
|
if self._uses_article_pdf_validation() else True)
|
|
540
585
|
if relevant:
|
|
541
586
|
try:
|
|
542
|
-
|
|
587
|
+
with watchdog.owned_by(captured["readers"]):
|
|
588
|
+
snippet = response.text()[:8192] if hasattr(response, "text") else response.body()
|
|
543
589
|
except Exception:
|
|
544
590
|
snippet = ""
|
|
545
591
|
text = self._visible_text_excerpt(snippet)
|
|
@@ -577,7 +623,7 @@ class CaptureMixin:
|
|
|
577
623
|
if self._should_defer_response_body(url):
|
|
578
624
|
captured["deferred_url"] = url
|
|
579
625
|
return
|
|
580
|
-
with transfer(result):
|
|
626
|
+
with transfer(result), watchdog.owned_by(captured["readers"]):
|
|
581
627
|
body = response.body()
|
|
582
628
|
# Body-level block-page detection (some block pages are 200
|
|
583
629
|
# with an HTML "IP Address Blocked" body).
|
|
@@ -819,6 +865,10 @@ class CaptureMixin:
|
|
|
819
865
|
if block_reason and not captured["block_reason"]:
|
|
820
866
|
captured["block_reason"] = block_reason
|
|
821
867
|
finally:
|
|
868
|
+
captured["closed"] = True
|
|
869
|
+
# A response still being read is not wanted any more (see watchdog.abandon).
|
|
870
|
+
if watchdog.abandon(captured["readers"]):
|
|
871
|
+
self._event(result, "pdf_response_read_abandoned", "capture ended")
|
|
822
872
|
finish()
|
|
823
873
|
if cdp_session is not None:
|
|
824
874
|
try:
|
|
@@ -503,5 +503,9 @@ class PublisherPlatformUnsupported(PublisherContentError):
|
|
|
503
503
|
"""The article is served only on a platform this engine cannot use (e.g. ClinicalKey)."""
|
|
504
504
|
|
|
505
505
|
|
|
506
|
+
class ArticleNotYetPublished(PublisherContentError):
|
|
507
|
+
"""The publisher lists the article as accepted; its full text is not online yet."""
|
|
508
|
+
|
|
509
|
+
|
|
506
510
|
class PublisherAccessBlocked(RuntimeError):
|
|
507
511
|
"""An explicit site security block, without an interactive verification."""
|
|
@@ -89,6 +89,7 @@ class DiagnosticsMixin:
|
|
|
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",
|
|
92
93
|
}:
|
|
93
94
|
activity.progress()
|
|
94
95
|
# Only publish fixed phase text; event details can contain signed URLs.
|
|
@@ -100,6 +101,8 @@ class DiagnosticsMixin:
|
|
|
100
101
|
"institution_entry_unresolved": ("官方机构入口尚未确认 CARSI", "checking_access"),
|
|
101
102
|
"login_state": ("检查机构登录页面", "checking_access"),
|
|
102
103
|
"idp_confirmation_required": ("请在浏览器里确认学校认证页的提示(信息发送同意、使用条款或二次验证)", "waiting_login"),
|
|
104
|
+
"idp_confirmation_accepted": ("已确认学校认证页的提示", "checking_access"),
|
|
105
|
+
"publisher_terms_accepted": ("已同意出版社的条款", "checking_access"),
|
|
103
106
|
"login_attempt_started": ("正在尝试机构登录", "checking_access"),
|
|
104
107
|
"login_retry_wait": ("机构登录暂未完成,准备重试", "checking_access"),
|
|
105
108
|
"login_navigation_interrupted": ("登录跳转中断,检查是否可重试", "checking_access"),
|
|
@@ -9,7 +9,8 @@ import time
|
|
|
9
9
|
from typing import Any
|
|
10
10
|
from urllib.parse import parse_qs, unquote, urlencode, urljoin, urlparse
|
|
11
11
|
|
|
12
|
-
from .batch_common import DownloadResult, _is_browser_error, logger, open_page,
|
|
12
|
+
from .batch_common import (DownloadResult, _is_browser_error, _is_navigation_cut, logger, open_page,
|
|
13
|
+
pump_until, settle)
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
def _school_auth_patterns(config: dict[str, Any]) -> tuple[str, ...]:
|
|
@@ -663,9 +664,11 @@ class InstitutionMixin:
|
|
|
663
664
|
# school failed the article, 2026-11-01): the page has gone on.
|
|
664
665
|
return True
|
|
665
666
|
|
|
667
|
+
# The school's name may follow "for" with no space: RSNA writes
|
|
668
|
+
# "for<em>Example University</em>" (2026-11-07).
|
|
666
669
|
_NO_INSTITUTION_SEARCH_RESULTS = re.compile(
|
|
667
|
-
r"^(?:no (?:institutions?|results?|matches) found(?:[.!]?$|\s+for
|
|
668
|
-
r"|we couldn['’]t find any results? for
|
|
670
|
+
r"^(?:no (?:institutions?|results?|matches) found(?:[.!]?$|\s+for)"
|
|
671
|
+
r"|we couldn['’]t find any results? for)", re.I)
|
|
669
672
|
_INSTITUTION_LIST_LINK = re.compile(r"^(?:select|choose) (?:your|an) institution from (?:a|the) list$", re.I)
|
|
670
673
|
|
|
671
674
|
def _handle_institution_search_miss(self, page: Any, result: DownloadResult, url: str) -> bool:
|
|
@@ -680,27 +683,35 @@ class InstitutionMixin:
|
|
|
680
683
|
if notice.is_visible() is not True:
|
|
681
684
|
return False # no candidate yet does not establish an empty result
|
|
682
685
|
message = notice.inner_text(timeout=800)
|
|
683
|
-
named = re.split(r"\bfor
|
|
684
|
-
for
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
if
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
and self._click_control(page, listing, result, "open institution list")):
|
|
698
|
-
self._event(result, "auto_institution_list_opened", url)
|
|
699
|
-
return True
|
|
700
|
-
return False # there is another route; don't call the school missing
|
|
701
|
-
self._event(result, "auto_institution_not_found", f"{message[:120]} @ {url}")
|
|
702
|
-
result._institution_not_listed = True
|
|
686
|
+
named = re.split(r"\bfor", message, maxsplit=1, flags=re.I)[1:]
|
|
687
|
+
ours = {q.rsplit(" @ ", 1)[0] for q in queries if q.endswith(f" @ {url}")}
|
|
688
|
+
typed = [str(box.input_value(timeout=800) or "").strip()
|
|
689
|
+
for box in (page.locator(selector).first for selector in self._institution_search_selectors(page))
|
|
690
|
+
if box.is_visible() is True]
|
|
691
|
+
if any(typed) and not any(value in ours for value in typed):
|
|
692
|
+
return False # the box holds another query now: the reply is not about ours
|
|
693
|
+
if named:
|
|
694
|
+
# The reply names the query it answers. RSNA's box, once it held the
|
|
695
|
+
# name, had lost the placeholder it was found by, and the miss went
|
|
696
|
+
# unseen until the page wait ran out (2026-11-08).
|
|
697
|
+
if not any(self._canonical_school_name(named[0]) == self._canonical_school_name(q) for q in ours):
|
|
698
|
+
return False # the reply names a different query
|
|
699
|
+
elif not any(value in ours for value in typed):
|
|
703
700
|
return False
|
|
701
|
+
listing = page.get_by_role("link", name=self._INSTITUTION_LIST_LINK).filter(visible=True).first
|
|
702
|
+
if listing.is_visible() is True:
|
|
703
|
+
href = listing.get_attribute("href", timeout=800)
|
|
704
|
+
if (href and self._manual_institution_target_allowed(urljoin(url, href))
|
|
705
|
+
and self._click_control(page, listing, result, "open institution list")):
|
|
706
|
+
self._event(result, "auto_institution_list_opened", url)
|
|
707
|
+
return True
|
|
708
|
+
if not any(e["state"] == "auto_institution_list_refused" and e.get("detail", "").endswith(url)
|
|
709
|
+
for e in result.events):
|
|
710
|
+
self._event(result, "auto_institution_list_refused", f"{str(href)[:160]} @ {url}")
|
|
711
|
+
return False # there is another route; don't call the school missing
|
|
712
|
+
self._event(result, "auto_institution_not_found", f"{message[:120]} @ {url}")
|
|
713
|
+
result._institution_not_listed = True
|
|
714
|
+
return False
|
|
704
715
|
except Exception as exc:
|
|
705
716
|
if not _is_browser_error(exc):
|
|
706
717
|
raise
|
|
@@ -742,24 +753,32 @@ class InstitutionMixin:
|
|
|
742
753
|
# A widget's accessible name can differ from its visible school
|
|
743
754
|
# text, or it can be a clickable div/span without a role. Use
|
|
744
755
|
# the visible control text, still requiring a click affordance.
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
const
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
return items.filter(el => !items.some(other => other !== el && el.contains(other)))
|
|
758
|
-
.slice(0,10).map((el,i) => {
|
|
759
|
-
el.setAttribute('data-paper-search-remembered', String(i));
|
|
760
|
-
return {i, text:(el.textContent || '').trim()};
|
|
756
|
+
try:
|
|
757
|
+
candidates = page.evaluate("""() => {
|
|
758
|
+
document.querySelectorAll('[data-paper-search-remembered]').forEach(e =>
|
|
759
|
+
e.removeAttribute('data-paper-search-remembered'));
|
|
760
|
+
const items = [...document.querySelectorAll('a,button,[role="button"],div,span')].filter(el => {
|
|
761
|
+
const native = el.matches('a[href],button,[role="button"]');
|
|
762
|
+
if (!native && el.closest('a,button,[role="button"]')) return false;
|
|
763
|
+
const text = (el.textContent || '').trim();
|
|
764
|
+
return text.length <= 160 && /^access through\\s*\\S/i.test(text)
|
|
765
|
+
&& el.getClientRects().length > 0 && getComputedStyle(el).visibility !== 'hidden'
|
|
766
|
+
&& !el.disabled && el.getAttribute('aria-disabled') !== 'true'
|
|
767
|
+
&& (native || typeof el.onclick === 'function' || getComputedStyle(el).cursor === 'pointer');
|
|
761
768
|
});
|
|
762
|
-
|
|
769
|
+
return items.filter(el => !items.some(other => other !== el && el.contains(other)))
|
|
770
|
+
.slice(0,10).map((el,i) => {
|
|
771
|
+
el.setAttribute('data-paper-search-remembered', String(i));
|
|
772
|
+
return {i, text:(el.textContent || '').trim()};
|
|
773
|
+
});
|
|
774
|
+
}""")
|
|
775
|
+
except Exception as exc:
|
|
776
|
+
if not _is_navigation_cut(exc):
|
|
777
|
+
raise
|
|
778
|
+
# The page navigated while it was read, e.g. the user chose
|
|
779
|
+
# a school (Karger's wayfinder): looked at again next pass.
|
|
780
|
+
self._event(result, "login_navigation_interrupted", "institution-entry")
|
|
781
|
+
return False
|
|
763
782
|
if isinstance(candidates, list):
|
|
764
783
|
for candidate in candidates:
|
|
765
784
|
label = re.sub(r"^\s*access through\s*", "", candidate["text"], flags=re.I)
|
|
@@ -422,8 +422,9 @@ class LoginMixin:
|
|
|
422
422
|
self._event(result, "login_state", marker)
|
|
423
423
|
last_state = marker
|
|
424
424
|
confirmation = self._idp_confirmation(page)
|
|
425
|
-
if confirmation:
|
|
426
|
-
#
|
|
425
|
+
if confirmation and confirmation not in self.IDP_ACCEPTED_CONFIRMATIONS:
|
|
426
|
+
# A second factor (Duo) is the user's; the agreements are
|
|
427
|
+
# accepted below (_accept_idp_confirmation).
|
|
427
428
|
self._event(result, "idp_confirmation_required", confirmation)
|
|
428
429
|
page_since = time.time()
|
|
429
430
|
elif self._user_away:
|
|
@@ -439,6 +440,8 @@ class LoginMixin:
|
|
|
439
440
|
continue
|
|
440
441
|
if self._return_from_login_site(page, result):
|
|
441
442
|
continue
|
|
443
|
+
if self._accept_publisher_terms(page, result) or self._accept_idp_confirmation(page, result):
|
|
444
|
+
continue
|
|
442
445
|
if manual_selection:
|
|
443
446
|
if self._is_challenge_page(page):
|
|
444
447
|
if not self._wait_for_challenge(page, result, deadline=deadline):
|
|
@@ -563,6 +566,91 @@ class LoginMixin:
|
|
|
563
566
|
: document.querySelector('[name="_shib_idp_consentOptions"], [name="_shib_idp_consentIds"]') ? 'attribute-release' : ''"""
|
|
564
567
|
_IDP_ERROR_RE = re.compile(r"未知错误|系统错误|服务异常|认证失败|出错了|\b5\d{4}\b.{0,20}错误|an unexpected error|error code|system error", re.I)
|
|
565
568
|
|
|
569
|
+
# A publisher's own terms form on the way to the school: SIAM's SAML consent
|
|
570
|
+
# ("I have read and agree to the Terms and Conditions and Privacy Policy.",
|
|
571
|
+
# Atypon's /action/saml2post) held the login until the page wait ran out
|
|
572
|
+
# (2026-11-07). The user asked to have such forms accepted (2026-11-08). Only
|
|
573
|
+
# on the publisher's site; the school's own: ``_accept_idp_confirmation``.
|
|
574
|
+
_PUBLISHER_TERMS_JS = r"""() => {
|
|
575
|
+
const visible = el => !!el && el.getClientRects().length > 0;
|
|
576
|
+
for (const form of document.querySelectorAll('form')) {
|
|
577
|
+
if (!visible(form)) continue;
|
|
578
|
+
const text = (form.innerText || '').replace(/\s+/g, ' ').trim();
|
|
579
|
+
if (text.length > 300 || !/^I (?:have read and )?(?:agree|accept) to the ?Terms\b/i.test(text)) continue;
|
|
580
|
+
const yes = [...form.querySelectorAll('input[type=submit], button[type=submit], button:not([type])')]
|
|
581
|
+
.find(el => visible(el) && !/^\s*(?:no|cancel|decline)\b/i.test(el.value || el.innerText || ''));
|
|
582
|
+
if (!yes) continue;
|
|
583
|
+
yes.setAttribute('data-papersearch-terms', '1');
|
|
584
|
+
return text.slice(0, 120);
|
|
585
|
+
}
|
|
586
|
+
return '';
|
|
587
|
+
}"""
|
|
588
|
+
PUBLISHER_TERMS_TRIES = 2
|
|
589
|
+
|
|
590
|
+
def _accept_publisher_terms(self, page: Any, result: DownloadResult) -> bool:
|
|
591
|
+
"""Agree to a publisher's terms form shown during the login; True when clicked."""
|
|
592
|
+
url = str(getattr(page, "url", "") or "")
|
|
593
|
+
if (not self._on_publisher_host(url) or self._is_idp_host(urlparse(url).netloc)
|
|
594
|
+
or sum(e["state"] == "publisher_terms_accepted" for e in result.events) >= self.PUBLISHER_TERMS_TRIES):
|
|
595
|
+
return False
|
|
596
|
+
try:
|
|
597
|
+
terms = page.evaluate(self._PUBLISHER_TERMS_JS)
|
|
598
|
+
except Exception as exc:
|
|
599
|
+
if not _is_browser_error(exc):
|
|
600
|
+
raise
|
|
601
|
+
return False
|
|
602
|
+
if not terms or not self._click_control(page, page.locator('[data-papersearch-terms="1"]').first,
|
|
603
|
+
result, "accept the publisher's terms"):
|
|
604
|
+
return False
|
|
605
|
+
self._event(result, "publisher_terms_accepted", f"{terms} @ {url[:160]}")
|
|
606
|
+
settle(page, 2_000)
|
|
607
|
+
return True
|
|
608
|
+
|
|
609
|
+
# The school's IdP asking to agree before it goes on (Shibboleth's attribute
|
|
610
|
+
# release and terms of use): accepted for the user too, as they asked
|
|
611
|
+
# (2026-11-08). The release keeps the choices the school preselected; the
|
|
612
|
+
# terms' own "I accept" box is ticked. A second factor (Duo) stays the user's,
|
|
613
|
+
# and so does a confirmation still shown after two accepts in one article.
|
|
614
|
+
IDP_ACCEPTED_CONFIRMATIONS = ("attribute-release", "terms-of-use")
|
|
615
|
+
IDP_CONFIRMATION_TRIES = 2
|
|
616
|
+
_IDP_ACCEPT_JS = r"""(kind) => {
|
|
617
|
+
const visible = el => !!el && el.getClientRects().length > 0;
|
|
618
|
+
const proceed = [...document.querySelectorAll('[name="_eventId_proceed"]')].find(visible);
|
|
619
|
+
if (!proceed) return false;
|
|
620
|
+
if (kind === 'terms-of-use' && proceed.form)
|
|
621
|
+
for (const box of proceed.form.querySelectorAll('input[type=checkbox][name="_shib_idp_consentIds"]'))
|
|
622
|
+
if (!box.checked && visible(box)) box.setAttribute('data-papersearch-idp', 'tick');
|
|
623
|
+
proceed.setAttribute('data-papersearch-idp', 'proceed');
|
|
624
|
+
return true;
|
|
625
|
+
}"""
|
|
626
|
+
|
|
627
|
+
def _accept_idp_confirmation(self, page: Any, result: DownloadResult) -> bool:
|
|
628
|
+
"""Agree to the school's attribute release or terms of use; True when clicked.
|
|
629
|
+
Otherwise the user is told once that the page waits for them."""
|
|
630
|
+
kind = self._idp_confirmation(page)
|
|
631
|
+
if kind not in self.IDP_ACCEPTED_CONFIRMATIONS:
|
|
632
|
+
return False
|
|
633
|
+
url = str(getattr(page, "url", "") or "").split("?", 1)[0]
|
|
634
|
+
if sum(e["state"] == "idp_confirmation_accepted" for e in result.events) < self.IDP_CONFIRMATION_TRIES:
|
|
635
|
+
try:
|
|
636
|
+
ready = page.evaluate(self._IDP_ACCEPT_JS, kind)
|
|
637
|
+
except Exception as exc:
|
|
638
|
+
if not _is_browser_error(exc):
|
|
639
|
+
raise
|
|
640
|
+
ready = False
|
|
641
|
+
if ready:
|
|
642
|
+
for box in page.locator('[data-papersearch-idp="tick"]').all():
|
|
643
|
+
self._click_control(page, box, result, "tick the school's terms of use")
|
|
644
|
+
if self._click_control(page, page.locator('[data-papersearch-idp="proceed"]').first,
|
|
645
|
+
result, "accept the school's confirmation"):
|
|
646
|
+
self._event(result, "idp_confirmation_accepted", f"{kind} @ {url[:160]}")
|
|
647
|
+
settle(page, 2_000)
|
|
648
|
+
return True
|
|
649
|
+
if getattr(result, "_idp_confirmation_left", "") != kind:
|
|
650
|
+
result._idp_confirmation_left = kind
|
|
651
|
+
self._event(result, "idp_confirmation_required", kind)
|
|
652
|
+
return False
|
|
653
|
+
|
|
566
654
|
def _idp_confirmation(self, page: Any) -> str:
|
|
567
655
|
"""What the school's IdP asks the user to agree to, if anything: Shibboleth's
|
|
568
656
|
attribute release or terms of use, or a Duo second factor."""
|
|
@@ -628,6 +716,7 @@ class LoginMixin:
|
|
|
628
716
|
r"|sorry, you have been blocked|no institutions found|not registered for use with this service"
|
|
629
717
|
r"|application you have accessed is not registered|may not be enabled for this type of authentication"
|
|
630
718
|
r"|can't find your institution|access to this resource has been restricted by your organization|oa-ap-4032"
|
|
719
|
+
r"|不支持的请求|does not have access to this resource"
|
|
631
720
|
r"|temporarily unavailable|verify you are human|are you a robot|checking your browser|正在进行安全验证", re.I)
|
|
632
721
|
|
|
633
722
|
def _login_block_reason(self, page: Any) -> str:
|
|
@@ -641,7 +730,9 @@ class LoginMixin:
|
|
|
641
730
|
if code == "login_page_closed":
|
|
642
731
|
return "the browser window was closed"
|
|
643
732
|
if code == "institution_pdf_entitlement_missing":
|
|
644
|
-
|
|
733
|
+
line = self._denial_line(page)
|
|
734
|
+
if line:
|
|
735
|
+
return line
|
|
645
736
|
lists = self._federation_list_lacks_carsi(page) if code == "institution_federation_unavailable" else ""
|
|
646
737
|
if lists:
|
|
647
738
|
return f"the federation list has no CARSI entry ({lists})"[:240]
|
|
@@ -698,6 +789,15 @@ class LoginMixin:
|
|
|
698
789
|
return override
|
|
699
790
|
if "unsupported request" in haystack and "not registered for use with this service" in haystack:
|
|
700
791
|
return "institution_not_registered"
|
|
792
|
+
# The same Shibboleth page in Chinese: "Web登陆服务 - 不支持的请求" on the
|
|
793
|
+
# school's IdP, the school has not enabled this publisher (JAMA, 2026-11-07).
|
|
794
|
+
if "不支持的请求" in haystack and self._is_idp_host(urlparse(current_url).netloc):
|
|
795
|
+
return "institution_not_registered"
|
|
796
|
+
# LibLynx (De Gruyter's chooser) after the school was chosen: "<school> does
|
|
797
|
+
# not have access to this resource", the publisher denies the school (2026-11-07).
|
|
798
|
+
if ("does not have access to this resource" in haystack
|
|
799
|
+
and any(name.lower() in haystack for name in self._institution_names() if name)):
|
|
800
|
+
return "institution_pdf_entitlement_missing"
|
|
701
801
|
if "application you have accessed is not registered" in haystack:
|
|
702
802
|
return "institution_not_registered"
|
|
703
803
|
if "your institution may not be enabled for this type of authentication" in haystack:
|
|
@@ -884,22 +984,27 @@ class LoginMixin:
|
|
|
884
984
|
|
|
885
985
|
# Controls that open a site's access menu or login panel instead of a page:
|
|
886
986
|
# "GET ACCESS" and "Login / Register" on ascelibrary.org (2026-11-02), "Access
|
|
887
|
-
# options", "Sign in". A link to a login page is not one of them.
|
|
987
|
+
# options", "Sign in". A link to a login page is not one of them. An access
|
|
988
|
+
# menu comes first: SIAM's "Register / Sign In", earlier on the page than its
|
|
989
|
+
# "Get Access", went to its personal account sign-in (2026-11-08).
|
|
888
990
|
_ACCESS_MENU_JS = r"""() => {
|
|
889
991
|
const shown = el => el.getClientRects().length > 0 && getComputedStyle(el).visibility !== 'hidden';
|
|
890
|
-
const
|
|
992
|
+
const MENUS = [/^(?:get access|access options)$/i,
|
|
993
|
+
/^(?:(?:log ?in|sign ?in)(?: ?\/ ?register)?|register ?\/ ?(?:log ?in|sign ?in))$/i];
|
|
891
994
|
const TOGGLES = ['aria-haspopup', 'aria-expanded', 'aria-controls', 'data-toggle', 'data-bs-toggle', 'data-target'];
|
|
892
|
-
for (const
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
995
|
+
for (const MENU of MENUS) {
|
|
996
|
+
for (const el of document.querySelectorAll('button, [role="button"], a')) {
|
|
997
|
+
if (!shown(el) || el.closest('form')) continue;
|
|
998
|
+
const label = (el.innerText || el.getAttribute('aria-label') || '').replace(/\s+/g, ' ').trim();
|
|
999
|
+
// A screen-reader hint can be part of innerText ("Sign In Open Menu").
|
|
1000
|
+
const menuLabel = label.replace(/\s+open menu$/i, '');
|
|
1001
|
+
if (!MENU.test(menuLabel)) continue;
|
|
1002
|
+
const href = (el.getAttribute('href') || '').trim();
|
|
1003
|
+
if (el.tagName === 'A' && href && !href.startsWith('#') && !/^javascript:/i.test(href)
|
|
1004
|
+
&& !TOGGLES.some(name => el.hasAttribute(name))) continue;
|
|
1005
|
+
el.click();
|
|
1006
|
+
return label;
|
|
1007
|
+
}
|
|
903
1008
|
}
|
|
904
1009
|
return '';
|
|
905
1010
|
}"""
|
|
@@ -35,6 +35,7 @@ _LOGIN_FAILURE_CODES = (
|
|
|
35
35
|
_FAILURE_KINDS = {
|
|
36
36
|
"publisher_content_error": ("publisher_content_error", "review_publisher_error"),
|
|
37
37
|
"unsupported_platform": ("unsupported_platform", "review_publisher_error"),
|
|
38
|
+
"article_not_yet_published": ("article_not_yet_published", "review_publisher_error"),
|
|
38
39
|
"browser_unresponsive": ("browser_unresponsive", "review_browser"),
|
|
39
40
|
"browser_operation_timeout": ("browser_operation_timeout", "review_browser"),
|
|
40
41
|
"publisher_access_blocked": ("access_blocked", "review_access"),
|
|
@@ -348,7 +349,8 @@ def _try_builtin_institutional(
|
|
|
348
349
|
# survives in source_failures. Neither is hidden by a later plain miss.
|
|
349
350
|
denial = next((f for f in failures if f.get("reason_code") ==
|
|
350
351
|
"institution_pdf_entitlement_missing"), None)
|
|
351
|
-
primary = next((f for code in ("source_exception", "unsupported_platform", "
|
|
352
|
+
primary = next((f for code in ("source_exception", "unsupported_platform", "article_not_yet_published",
|
|
353
|
+
"generic_institution_entry_missing",
|
|
352
354
|
"publisher_content_error", "access_blocked", *_LOGIN_FAILURE_CODES,
|
|
353
355
|
"download_timeout")
|
|
354
356
|
for f in failures if f["error_type"] == code), denial or failures[-1])
|
|
@@ -556,7 +558,8 @@ def _try_browser_batch_download(
|
|
|
556
558
|
# page is unreachable, so do not wait on it a second time.
|
|
557
559
|
result.supplements = [{"status": "skipped", "reason": "challenge_timeout",
|
|
558
560
|
"url": "", "label": ""}]
|
|
559
|
-
elif result.state in ("unsupported_platform", "
|
|
561
|
+
elif result.state in ("unsupported_platform", "article_not_yet_published",
|
|
562
|
+
"publisher_access_blocked", "publisher_unreachable",
|
|
560
563
|
"login_page_closed", "user_skipped", "batch_stopped",
|
|
561
564
|
"user_marked_no_entitlement"):
|
|
562
565
|
# Nothing more to fetch there now.
|