ClinicalTrials.gov Scraper: Study Details
A clinicaltrials.gov scraper fights a JavaScript shell that hides the study. Tested routes with real output: one command, the free API, schema extraction.

On this page
ClinicalTrials.gov publishes 609,114 study records, a free API for every one of them, and study pages that still hand a plain HTTP fetch an empty shell. I know the count because I asked the API; I know the shell because I fetched a study page and got 94,251 bytes of HTML containing zero occurrences of the drug being tested. That tension is the whole story of building a clinicaltrials.gov scraper in 2026, and this page is the scorecard: what the site serves, the one-command route to a full study record, when the API wins outright, and how to get study details into typed, structured data without writing a parser.
The ground rules first. This is a US government registry; its terms and conditions govern reuse of the data, and the site’s robots.txt disallows the API paths and search endpoints to crawlers while explicitly allowing its SEO sitemap, with a Crawl-delay of 1 second. Study pages themselves are not disallowed. That is the map, not legal advice; Is Web Scraping Legal? is the plain-English version. Everything below ran October 17–29, 2026, from a home connection; the site numbers were re-verified October 29 against the same study. Sites change, and this one changes daily by design: trial statuses flip.
What a ClinicalTrials.gov scraper is actually up against
The modernized ClinicalTrials.gov is a single-page application. Request a study page with curl and you get the app’s bootstrap shell, not the study. The National Library of Medicine said this plainly in a July 2025 TechBulletin: screen scraping gets you “bootstrap javascript code,” and the API is the intended route. I confirmed it live against the ACTT-1 remdesivir trial:
raw HTML 94,251 bytes, <title> = "ClinicalTrials.gov", 0 mentions of "Remdesivir"
--render static 111 chars (the shell's one line of static text, nothing else)
default render 27,126 chars / ~3,900 words in 7.9 seconds
The third line is Magpie, a local Go scraper whose default fetch escalates to a real browser when the static response is a JS shell. It rendered the page the way your browser does, and every section arrived: the brief summary, inclusion and exclusion criteria, the arms-and-interventions table, the full outcome-measure tables, contacts. There is no clinicaltrials vertical in Magpie’s 27 zero-LLM extractors; this is the generic scrape pipeline doing its normal job. The study page also carries no JSON-LD, so there is no schema.org shortcut to metadata on this site.
One politeness note before the routes. The robots.txt comment says the crawl delay means one second between calls for well-behaved crawlers. Browser-rendered pages are the expensive kind for the site to serve, so keep the pace human: one study at a time, or the API below.
The free API, and when it wins outright
NLM is not asking you to give up. Every study is one unauthenticated GET away:
curl -s "https://clinicaltrials.gov/api/v2/studies/NCT04280705" -o study.json
That file was 212,807 bytes of JSON nested 11 levels deep, organized into protocolSection, resultsSection, documentSection, and derivedSection. Every fact on the page is in there, typed and complete: overallStatus: "COMPLETED", actual enrollment 1,062, every outcome measure with its units. For machine consumption this is the correct source, and scraping pages for the same facts is wasted work. The search side is just as direct. query.cond filters by condition; fields= trims the response (the same study reduced to the 11 fields I cared about: 743 bytes); pageSize goes up to 1,000 per page, and asking for 1,001 gets you 1,000 back with no error, so paginate with nextPageToken until it disappears; countTotal=true adds the match count, which is how I got 609,114.
For anything bigger than a few thousand studies, NLM itself points to three more routes: the search-results UI’s Download button, which exports CSV, JSON, or RIS (30 fields for CSV, a zip-of-per-study-files option for JSON); a FHIR endpoint in pilot; and the CTTI AACT database, which ships the whole registry as a relational database for analysts. If you want none of the above and prefer no code at all, Apify lists at least six ClinicalTrials.gov scrapers, which means running someone else’s code in someone else’s cloud to fetch the same public data. Scraping 5,000 study pages one browser render at a time, at one second plus six seconds of rendering per page, is how you burn an afternoon and an IP reputation for data the API would hand you in minutes. The pages are for reading. The API is for counting.
One study page in one command
The page still has value: it is the human-readable record, already organized the way a clinician or a rival’s analyst reads it. To pull one, this is the whole program:
magpie scrape "https://clinicaltrials.gov/study/NCT04280705"
What came back, abridged:
{
"url": "https://clinicaltrials.gov/study/NCT04280705",
"title": "Study Details | NCT04280705 | Adaptive COVID-19 Treatment Trial (ACTT) | ClinicalTrials.gov",
"markdown": "This study is an adaptive, randomized, double-blind, placebo-controlled trial ...
Inclusion Criteria: Has laboratory-confirmed SARS-CoV-2 infection ...
| Participant Group/Arm | Intervention/Treatment |
| 200 mg of Remdesivir placebo ... n=286. | ... |
| Time to Recovery | ... | Day 1 through Day 29 | ..."
}
The arms and outcomes arrive as GFM tables, the eligibility text as prose, the contact emails intact. This is a completed trial, so the record is stable; on an actively recruiting study the same command works, just expect the content to keep changing underneath you.
What the cleaned page loses matters, though, and it sets up the next section. I counted. In those 27,126 chars, the string NCT04280705 appears zero times (it lives in the <title>, which cleaning drops), the word “Completed” appears zero times (the status is a UI chip, not body content), and the actual enrollment of 1,062 appears zero times, while the projected initial sample of 572 appears once, inside the brief summary. A human skims past those losses. An LLM does not.
Structured study details, two ways
Way one: schema-driven extraction against the page. Magpie takes a JSON Schema, sends the cleaned markdown to the LLM you point it at, and validates the reply against the schema with a repair loop. How to Extract Structured Data From Text covers the mechanics; here is the study version:
magpie scrape "https://clinicaltrials.gov/study/NCT04280705" \
--schema study.schema.json \
--provider openrouter --model deepseek/deepseek-chat-v3-0324
The schema asked for nct_id, title, status, sponsor, conditions, interventions, enrollment, ages, and the primary outcome. Real output, verbatim:
{
"extracted": {
"brief_title": "Adaptive Randomized Trial of Novel Therapeutic Agents for COVID-19",
"conditions": ["COVID-19"],
"enrollment": 572,
"minimum_age": "18 Years",
"nct_id": "unknown",
"overall_status": "Recruiting",
"primary_outcome": "Time to recovery by Day 29",
"sponsor": "National Institute of Allergy and Infectious Diseases (NIAID)"
},
"usage": {
"provider": "openrouter",
"model": "deepseek/deepseek-chat-v3-0324",
"prompt_tokens": 5708,
"completion_tokens": 102,
"usd_estimate": 0.0017716,
"attempts": 0
}
}
Three fields are wrong, and the API knows why. The trial is COMPLETED, not recruiting; the enrollment is 1,062, not 572; the NCT ID is NCT04280705, not “unknown”. Every miss traces to the counting in the last section: the model was asked for values the cleaned page does not contain, so it took the one number present (572, “projected”), and invented the rest. Note that marking nct_id as required did not help. Required forces the model to answer; it cannot force the page to contain the answer. The run cost $0.0018 and took 14.4 seconds, which is cheap garbage if you trust it and cheap if you don’t.
Way two is the fix, and it uses the same extractor against the API’s own answer:
curl -s "https://clinicaltrials.gov/api/v2/studies/NCT04280705?fields=NCTId,BriefTitle,OverallStatus,LeadSponsorName,Condition,InterventionName,EnrollmentCount,Sex,MinimumAge,MaximumAge,PrimaryOutcomeMeasure" \
-o study.json
magpie extract study.json --content-type markdown \
--schema study.schema.json \
--provider openrouter --model deepseek/deepseek-chat-v3-0324
{
"extracted": {
"brief_title": "Adaptive COVID-19 Treatment Trial (ACTT)",
"conditions": ["COVID-19"],
"enrollment": 1062,
"interventions": ["Placebo", "Remdesivir"],
"nct_id": "NCT04280705",
"overall_status": "COMPLETED",
"primary_outcome": "Time to Recovery",
"sex": "ALL",
"sponsor": "National Institute of Allergy and Infectious Diseases (NIAID)"
}
}
Nine for nine, in 4.7 seconds, with the prompt shrunk from 5,708 tokens to roughly two hundred (the trimmed response is 743 bytes). You skip the 11-level JSON navigation without writing a parser, and you skip the page render without losing a single fact. The general lesson travels: for LLM extraction cost, the input source matters more than the model. Feed the LLM the cleanest true source, not the prettiest page.
Watch a trial for status changes
Trial records are living documents. A study you care about flips from “Not yet recruiting” to “Recruiting”, or posts results years after completion, and nobody emails you. Magpie’s watch mode hashes a page and diffs on change:
magpie watch "https://clinicaltrials.gov/study/NCT07532265" --every 5m --once
I ran that against a currently recruiting asthma trial. First run: baseline, silent, 6.3 seconds, exit 0. Second run: no change, silent again, 7.4 seconds. That silence is the feature; you only hear from it when something changed, and then you get a word-diff plus an optional --webhook POST carrying {url, changed, old_hash, new_hash, diff}. --once is the cron mode: put the command in crontab, keep --every 5m as the interval floor, and one check per five minutes against one study page is well inside polite. Watch the study’s own URL, not a search results page; robots.txt disallows the search endpoints to crawlers.
Which route, when
| You need | Route |
|---|---|
| One study, human-readable | magpie scrape the study URL |
| Typed fields from one study | API fields= fetch, then magpie extract --schema |
| Every study matching a condition | API search: query.cond, pageSize=1000, nextPageToken loop |
| The entire registry for analysis | CTTI AACT database |
| An alert when a trial changes | magpie watch on the study URL |
FAQ
Is it legal to scrape ClinicalTrials.gov? The data is a US government registry’s public record and the terms and conditions govern reuse; NLM asks bulk users to prefer the API and AACT. robots.txt disallows the API and search endpoints to crawlers; study pages are permitted. Not legal advice.
Why does my Python scraper get an empty page? The site is a single-page application. requests and BeautifulSoup see the bootstrap JavaScript shell, which is why NLM’s 2025 bulletin steers screen scrapers to the API. You need a browser-rendering scraper or the API.
Is there an official ClinicalTrials.gov API?
Yes, API v2, free, no key. Single-study GET plus a search endpoint with condition/status filters, field selection, pages of 1,000, and countTotal=true for match counts. FHIR is in pilot.
How do I download all studies for a condition?
Loop the search API with nextPageToken until it disappears, use the search UI’s Download button for CSV/JSON/RIS up to a result set you can click through, or use CTTI’s AACT for the whole database.
Do study pages have JSON-LD or schema.org data? None that my runs found; Magpie’s JSON-LD sidecar came back empty on study pages. The structured source on this site is the API, not the page markup.
The first command to run
If you came here for one study, run the one-liner above and read the markdown. If you came for a cohort, start with the API’s field selector, because a 743-byte response beats a 213 KB one and a 27,000-character page alike. And if you came for typed rows without writing a JSON navigator, the extract command against the API is the shortest path I tested. More site-specific guides live at Scrapers for Popular Websites, including the closest cousin to this one: the arXiv scraper for pulling research papers instead of trials.


