Skip to content

21 — Repository-harvest spider: ingest JSON:API / paginated-JSON collections - #19

Open
MirjamOdile wants to merge 2 commits into
mainfrom
pr/21-repository-harvest
Open

21 — Repository-harvest spider: ingest JSON:API / paginated-JSON collections#19
MirjamOdile wants to merge 2 commits into
mainfrom
pr/21-repository-harvest

Conversation

@MirjamOdile

@MirjamOdile MirjamOdile commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

What was broken: institutional research repositories (Islandora, DSpace, Fedora fronts) are often effectively uncrawlable as HTML: a Cloudflare Turnstile puzzle on every page plus a Crawl-delay: 120 robots rule means ~20–30k documents would take weeks — while the same sites expose a fully open, puzzle-free machine API (Drupal JSON:API) that lists the complete repository. scrapai had no way to ingest a paginated JSON collection.

What it does now: a new spider type walks the JSON collection endpoint page by page and maps each record into a normal pipeline item. The mapping lives entirely in the spider's JSON config (REPOSITORY_SOURCE): field dot-paths with || fallbacks, JSON:API include relationship resolution, URL templates, and the standard processor chain. Setting it routes the crawl to the new spider; every existing HTML/sitemap spider is untouched.

Details

  • New spiders/repository_spider.py (repository_database_spider): follows the next link until absent; records failing a require field (e.g. unpublished parent omitted from included) are skipped, not errored.
  • cli/crawl.py: a non-empty REPOSITORY_SOURCE setting routes to it, alongside the existing USE_SITEMAP routing.
  • First target: an institutional research repository (~20–30k PDFs) — weeks of Turnstile crawling become one polite pass.
  • Note: the config validator caps DOWNLOAD_DELAY at 60, so spiders honoring a Crawl-delay: 120 import with --skip-validation.
  • Request doc: docs/requests/21-jsonapi-repository-harvest.md (port of the pre-migration repo's request 11).

Behavior changes

  • None for existing spiders: the new spider only activates when a config sets REPOSITORY_SOURCE; all HTML/sitemap routing is untouched.

Verified

8 unit tests (tests/unit/test_repository_spider.py): dot-path walker, || fallbacks, full item mapping (template + include resolution + processors), missing-include → null, require skip, pagination follow and stop, malformed records, item-limit cutoff. The design is a port of code proven in production in the pre-migration repo.

Merge note: touches cli/crawl.py, as do PRs 17/18/19 — merging in numeric order minimizes conflicts.

Institutional repositories (Islandora/DSpace/Fedora) are often un-crawlable as
HTML (Turnstile on every page, Crawl-delay: 120, homepage-only sitemap, broken
OAI-PMH) yet expose an open machine API enumerating the full repository. New
repository_database_spider walks the paginated collection endpoint and maps
each record to a normal pipeline item via the REPOSITORY_SOURCE setting
(dot-paths, || fallbacks, JSON:API include resolution, URL templates, standard
processors). A non-empty REPOSITORY_SOURCE routes the crawl to it; HTML and
sitemap spiders are untouched. 8 unit tests.

docs/requests/21-jsonapi-repository-harvest.md (port of the old repo's request 11)
@iRanadheer
iRanadheer force-pushed the pr/21-repository-harvest branch from 7ec1161 to c4954e9 Compare August 10, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant