Building an NHS Evidence Scraper
The scraper I built gathers board papers, strategies and datasets from 47 mental health trusts, 42 ICBs and eight national sources, and logs broken NHS websites for repair.
Public sector transparency in Britain operates on a fascinating principle: every important document is completely public, legally published, and hidden inside a fourth-level accordion menu on a Drupal site from 2014.
Say you want to answer a straightforward question across NHS mental health services, such as which trusts have published a new digital strategy this year, or how many board packs mention a specific waiting-time pressure.
There are 47 mental health trusts and 42 Integrated Care Boards (ICBs). One trust publishes its board papers as a single 420-page PDF called Board_Pack_FINAL_v3_amended(1).pdf. The next splits every agenda item into twenty separate Word documents hosted on a third-party domain. A third renders its entire document library via client-side JavaScript that only fires if you scroll past a cookie banner. Doing that by hand takes days of opening tabs, losing your place, and questioning your life choices.
So I built the NHS Evidence Scraper to do the tab-opening for me.
47 trusts, 42 ICBs and 8 national datasets
The temptation with a project like this is to jump straight to sticking a language model on top of everything. That is completely backwards. An LLM cannot summarise a board paper if your crawler got blocked by a 403 error three directories up, or downloaded the catering menu from 2019 instead of the annual Quality Account.
The scraper starts with coverage and provenance. It walks 47 mental health trusts, 42 ICBs and eight national datasets (including the Mental Health Services Data Set and QOF), pulling board packs, annual reports, quality accounts, strategies and CQC inspection reports. Every downloaded file gets a normalised filename and a JSON metadata sidecar recording the exact URL, organisation, publication date and document classification.
Why NHS websites break crawlers
A naive web scraper assumes that if a URL worked on Monday, it will work on Thursday. NHS websites do not subscribe to this philosophy.
During normal runs, organisations routinely:
- rename their
/publications/directory to/about-us/corporate-information/board-meetings-2026/without redirects; - offload PDF hosting to an external CDN or SharePoint tenant that rejects requests outside a specific domain;
- start returning
HTTP 429 Too Many Requestsafter six rapid page loads.
If your script treats every failed download as a transient blip, it will happily spend forty minutes retrying a dead URL every time you run it.
Instead, the scraper treats failure as persistent operational data. Every run writes to a failure history log. If a trust’s publications page fails repeatedly, the dashboard flags that specific organisation as broken rather than silently omitting its papers from your search results. Known-good index pages are cached and checked first on future runs, and a built-in organisation editor lets you update a trust’s starting URL or whitelisted document domains in the UI without digging through config files.
Politeness as a feature
Scraping public healthcare websites requires manners. You are sharing bandwidth with people trying to look up clinic hours and parking charges.
The session layer respects Retry-After headers automatically, backs off exponentially on 429 and 503 responses, and gives the operator explicit sliders for worker concurrency, lookback window and per-request delay. Trust crawls, ICB crawls and national dataset pulls run in separate progress streams, and the whole run exports cleanly to CSV alongside the raw files and metadata sidecars.
I have an experimental layer in the repo for searching inside the downloaded PDFs and extracting structured priorities, which I still treat as a work in progress. Honestly, the dull part is the part that saves all the time: knowing that 97 separate public bodies have been checked, knowing which three moved their websites this month, and having the PDFs sitting in a folder before you have finished your first cup of tea.