Court website scraping
Court website scraping brings new opinions, oral arguments, and state docket records into CourtListener from public court sites and court update services. It turns source-specific results into shared court records, prevents repeat storage, and sends new files to later text, citation, and search work.
System boundary
The scraping system sits between external court sites and the court-record systems described in Court records. A scraper finds new or changed material and passes it to persistence and processing flows. State docket collection can also feed the RECAP case-record flow described in RECAP case records.
The main collection paths are:
| Source | Main result | Collection style |
|---|---|---|
| Court opinion and audio sites | Opinions or oral arguments grouped with dockets | Repeated polling or a bounded backfill |
| State docket sites | Docket pages, entries, and attachments | Polling for changes, then case collection |
| Court email services | Notifications about state or Supreme Court updates | Authenticated intake followed by an asynchronous processor |
Scraper definitions
Court source definitions
Each court source has a Juriscraper site definition. The definition describes how to find source records and expose common fields. The collection service selects it from a court ID and target type. A full module path is used when one court ID maps to more than one source. cl/…/juriscraper_utils.py resolves these definitions and supports text extraction after a document is stored.
The definition-to-record contract is shared across sources. Collection needs enough data to identify the court record, date, case, and document. A field change can affect docket matching, duplicate checks, and later metadata work at the same time.
References: cl/…/juriscraper_utils.py• L17-54 cl/…/juriscraper_utils.py• L57-95 cl/…/cl_scrape_opinions.py• L280-343
Polling and collection
Opinion and audio collection
Opinion collection uses cl/…/cl_scrape_opinions.py as its main path. It loads a site definition, reads case results, checks each document, and creates or updates the shared docket, case grouping, opinion, and citation records. A case result can contain more than one opinion, so the collector keeps those documents together and preserves their order. The related oral-argument path applies the same source and duplicate model to audio files. New documents enter asynchronous extraction and citation work. New audio enters audio processing.
The normal run stops when the source page is unchanged or when the result stream reaches its duplicate limit. A full crawl or a date-bounded backfill reads older source material without normal freshness stops. Daemon mode repeats the court cycle for ongoing coverage. A safe stop finishes the current court before exit.
This diagram shows how a court result becomes a stored and searchable court record.
flowchart LR
A[Court site] --> B[Scraper definition]
B --> C[Case and file result]
C --> D{Already known?}
D -- No --> E[Docket and opinion or audio record]
E --> F[Text, citation, version, or audio processing]
D -- Yes --> G[Skip or stop current crawl]
References: cl/…/cl_scrape_opinions.py• L280-343 cl/…/cl_scrape_opinions.py• L381-429 cl/…/cl_scrape_opinions.py• L431-487 cl/…/cl_scrape_oral_arguments.py• L125-180 cl/…/tasks.py• L135-269 cl/…/tasks.py• L724-783
State polling and backfill
State pollers look for changes in systems that expose dockets rather than opinion lists. A poll cycle searches a recent time window, removes repeated case updates, fetches the complete case when needed, archives the source response or parsed case, and dispatches ingestion work. A backfill covers a date range when polling finds a gap or historical coverage is required.
The shared backfill path uses rate limits, retries for access errors and timeouts, batch boundaries, and Redis checkpoints. Checkpoints expire after four weeks, and an auto-resume run starts from the saved end date when requested. Florida can rescrape selected cases by UUID and skip parsed files already in its archive. Texas TAMES compares a recent result snapshot, stops a backfill at a known case, and retries pending CaseMail subscriptions after collection. Florida polling keeps an overlap between cycles and writes each cycle under a time-based archive prefix.
State scrapers can archive successful responses or load them from the archive for replay and re-ingestion. Archive writes use a queued task and a queue throttle, so storage work does not add the full write delay to the collection loop.
References: cl/…/utils.py• L68-166 cl/…/utils.py• L180-284 cl/…/utils.py• L287-407 cl/…/back_scrape_dockets.py• L40-53 cl/…/back_scrape_dockets.py• L365-417 cl/…/back_scrape_dockets.py• L522-613 cl/…/back_scrape_fl_dockets.py• L78-163 cl/…/back_scrape_fl_dockets.py• L245-303 cl/…/tames_poller.py• L326-472 cl/…/fl_poller.py• L195-285 cl/…/tasks.py• L1106-1135
Citation and text refresh
Some court pages gain citation or metadata fields after first publication. Citation backfills match the downloaded file to an existing opinion when possible and add missing citations. If the opinion is not known, they use the normal ingestion path. Text refreshes run the source parser over stored content so that docket, cluster, opinion, originating-court, and citation data can be corrected without another source request.
References: cl/…/cl_back_scrape_citations.py• L25-120 cl/…/update_from_text.py• L21-105 cl/…/tasks.py• L74-132
Duplicate checking
Crawl freshness
The scraper records a hash for each source URL. On a normal crawl, an unchanged hash means the source has not reported new material, so the crawl can stop before it reads the same page again. The hash is saved only after the crawl finishes without bad document content. A bad response or bad document remains eligible for another try. Full crawls ignore the source hash for stopping and do not update it.
References: cl/…/DupChecker.py• L51-86 cl/…/cl_scrape_opinions.py• L287-343
Document identity
Document checks protect the corpus when a collected item would be saved. They use content hashes in most cases. They use the source download URL for sources whose files change while the legal document stays the same. The collector tracks duplicate results during a crawl. A run of known documents can mean that a court is current, so the collector can stop a normal crawl instead of scanning covered history.
Full crawls still reject each duplicate, but do not use duplicate runs as a stop signal. This permits historical reprocessing without weakening the normal polling guard. Florida polling also removes repeated updates for the same case before it fetches a full case from more than one update source.
Duplicate cleanup handles records that entered the corpus before a source rule was corrected. It can merge exact-hash duplicates, cleaned-content duplicates, and selected identical-text cases. Version merging groups court-site opinions that share a download URL. It keeps the newest matching opinion as the main record when docket identity, comparable text length, and text similarity support that relation. Loose text matches require stricter metadata agreement. Related records are redirected to the main record.
References: cl/…/DupChecker.py• L88-161 cl/…/cl_scrape_opinions.py• L381-429 cl/…/fl_poller.py• L287-316 cl/…/delete_duplicates.py• L118-190 cl/…/delete_duplicates.py• L207-329 cl/…/merge_opinion_versions.py• L691-765 cl/…/merge_opinion_versions.py• L766-937
Persistence and downstream processing
Court record persistence
Collected metadata is matched to an existing docket when possible. The matching rules use the court and docket number, with source-specific handling for federal and state records. A case-name difference that looks like a possible mismatch is not allowed to overwrite the existing name. The system stores the case grouping and each opinion as a court-sourced record. Citations and lower-court information stay linked to that record. This keeps repeated source visits from creating a second case for the same docket.
The stored file is the handoff point for later work. Text extraction can use OCR when needed, update metadata found in the file, merge matching court-site versions, and start citation linking and search-alert processing. Audio files follow a parallel handoff to conversion and audio metadata processing.
References: cl/…/utils.py• L192-247 cl/…/utils.py• L309-432 cl/…/cl_scrape_opinions.py• L84-235 cl/…/cl_scrape_opinions.py• L431-481 cl/…/tasks.py• L141-269 cl/…/tasks.py• L724-783
Response archives
Source responses can be kept in private object storage. Archives preserve raw responses, headers, and state-case metadata for review, parser repair, replay, and later ingestion without another court request. State collectors can also archive parsed case data.
Archive use is optional for live collection. Cached responses support replay and do not replace fresh polling when the goal is to find updates. Archive writes can run through a task queue so collection can continue while storage work completes. Florida uses separate time-based prefixes for polling cycles so earlier responses remain available.
References: cl/…/utils.py• L466-497 cl/…/utils.py• L287-407 cl/…/back_scrape_dockets.py• L254-301 cl/…/back_scrape_fl_dockets.py• L29-53 cl/…/fl_poller.py• L219-285 cl/…/tasks.py• L1106-1135
Record repair and import tools
Administrative commands support controlled repair and development work around the live scraper flow. Operators can reprocess stored text, merge or remove duplicate opinion records, fetch Harvard corpus files from Internet Archive, and clone selected CourtListener records into a development database. The clone tool can include related dockets, opinions, audio, docket entries, and files when requested. It is development-only and requires an API token. These tools support recovery, migration, or local investigation. They do not replace normal source polling.
References: cl/…/update_from_text.py• L110-217 cl/…/merge_opinion_versions.py• L939-998 cl/…/delete_duplicates.py• L334-425 cl/…/scrape_harvard_ia.py• L28-100 cl/…/scrape_harvard_ia.py• L115-167 cl/…/clone_from_cl.py• L163-320 cl/…/clone_from_cl.py• L421-629 cl/…/clone_from_cl.py• L1070-1259
Administrative tools
Scraper status reports
The admin area gives operators a view of source freshness and collection results. URL hashes show the freshness markers used by normal crawls. PACER free-document logs and rows show the state of that separate document collection path.
The latest-opinion report groups the newest stored opinion by court and shows how long it has been since that court produced one. It helps expose a scraper that fails quietly while its process stays active. The report must be refreshed before it reflects recent records.
References: cl/…/admin.py• L13-38 cl/…/admin.py• L41-75 cl/…/refresh_scrapers_status_view.py• L8-22 cl/…/models.py• L11-83
Subscription tracking
State update services can subscribe to cases so later court changes arrive as email events. The scraper records the account and the date range covered by successful subscriptions. Failed subscriptions remain pending for a later poll cycle. The account record keeps one subscription range per scraper user.
References: cl/…/tames_poller.py• L143-243 cl/…/models.py• L114-157
Scraper-facing views
Court update email intake
The scraper-facing API accepts structured email events from supported court notification services. It validates the court, source, message data, and receipt data. It stores the event in the email-processing queue and dispatches the source-specific processor. The endpoint does not parse the court update itself. It hands that work to an asynchronous task.
For Supreme Court notifications, the processor distinguishes docket-entry, confirmation, and invalid messages. An invalid message sets the queue item to invalid content and stops without fetching or merging a docket. Confirmation results record success or failure. Docket-entry results continue to court-record merging.
Texas TAMES and Supreme Court notifications use separate routes and source markers. The route-to-task mapping also sets the service account that owns the queued event. A new source must preserve the link between route, court, uploader, source type, and processor.
This diagram shows the boundary between an external notification service and court-record ingestion.
sequenceDiagram
participant S as Court notification service
participant V as Scraper-facing API
participant Q as Email processing queue
participant P as Source processor
S->>V: Send validated email event
V->>Q: Store event and source metadata
V->>P: Dispatch queued event
P->>Q: Add or update court records
References: cl/…/views.py• L36-45 cl/…/views.py• L47-109 cl/…/views.py• L112-172 cl/…/views.py• L175-221 cl/…/tasks.py• L4144-4203 cl/…/tests.py• L3012-3042
Change checklist
When these files or sections are changed, remember to consider these:
- A new opinion or audio source must keep its court ID aligned with the court record and its enabled-scraper state.
- A change to scraper field names must be checked against docket matching, case grouping, citation creation, text extraction, and version matching.
- A change to duplicate identity must preserve the difference between source freshness checks, per-file duplicate checks, and later version merging.
- A new state poller must align its update identity with its snapshot or checkpoint key, archive key, known-record lookup, and ingestion task.
- A change to state poll overlap or checkpoint dates must preserve coverage at cycle boundaries and account for checkpoint expiry.
- A change to archived response names or request keys must keep live collection, replay, cached backfill, and queued ingestion able to find the same source data.
- A new email source must update route validation, source marker, service account, and asynchronous processor as one contract.
- A change to the latest-opinion report must keep its materialized-view refresh process aligned with the admin model.
- A change to version similarity or metadata rules must keep the main-version link, cluster redirection, search removal, and related-object repointing consistent.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A source hash is saved after a missed or partial scrape | The next normal crawl can skip the source | Save the hash only after a clean crawl and inspect the status report |
| A source returns several known documents in the current order | The collector can stop and miss newer records when source ordering is wrong | Review duplicate-run logs and use a bounded or full crawl for recovery |
| A court changes a document while keeping its URL | URL identity can hide a changed file | Use content identity where stable and run extraction or a full crawl when source behavior changes |
| A state poller cannot find its known case or checkpoint | The run can contain a silent coverage gap | Review gap logs and use overlap, checkpointed backfill, or archive replay |
| The same Florida case appears in both update feeds | The system can fetch and queue the full case more than once | Deduplicate updates by case UUID before fetching |
| A source returns 403 responses or timeouts beyond retry limits | Collection stops without complete coverage | Rate limits and backoff reduce load; operator review is still required |
| A version candidate has a different docket, a large length gap, or weak text match | A repair task can leave duplicates or merge unrelated records | Compare docket identity, text length, and text similarity before merging |
| An archive request key changes without a replay migration | Cached backfills can miss stored responses and request them again | Keep request-key construction aligned with archive readers and writers |
| An email route has missing fields or an unsupported court/source pair | The event is rejected or no processor is selected | Validate the payload and route mapping before dispatch |
Key files
| File | Why to read it |
|---|---|
| cl/…/cl_scrape_opinions.py | Main opinion collection flow from source result to stored court records |
| cl/…/cl_scrape_oral_arguments.py | Audio collection flow and handoff to audio processing |
| cl/…/DupChecker.py | Freshness and duplicate decisions that control crawl stopping |
| cl/…/utils.py | Shared state backfill, checkpoint, rate-limit, and archive behavior |
| cl/…/tames_poller.py | Snapshot polling, bounded backfill, archive handoff, and notification subscriptions |
| cl/…/fl_poller.py | Florida update polling, case deduplication, overlap, and queued ingestion |
| cl/…/back_scrape_dockets.py | Generic state backfill with retries, batching, checkpoints, and response persistence |
| cl/…/back_scrape_fl_dockets.py | Florida backfill, targeted rescraping, parsed-file checks, and queued storage |
| cl/…/utils.py | Docket matching, citation checks, source response archiving, and scraper-to-record helpers |
| cl/…/tasks.py | Asynchronous document extraction, metadata refresh, version checks, audio processing, and response storage |
| cl/…/merge_opinion_versions.py | Safe merging of opinion versions and related court records |
| cl/…/clone_from_cl.py | Development-only import of selected CourtListener records and related files |
| cl/…/scrape_harvard_ia.py | Harvard corpus retrieval from Internet Archive |
| cl/…/views.py | API boundary for scraper-facing court email events |
| cl/…/tasks.py | Processing states and record updates for Supreme Court email events |
| cl/…/admin.py | Operator reports for source freshness and collection state |