PubMed Scraper: Search Results & Abstracts

A tested PubMed scraper walkthrough: search results, full abstracts, MEDLINE records via one toggle, and the free E-utilities API, with real output.

MMotherlode Lab9 min read
Magpie title card: PubMed Scraper: Search Results & Abstracts

PubMed is the rare large site that still serves its content pages as plain, complete HTML. I fetched a search for remdesivir with curl and got 252,904 bytes of server-rendered results: titles, authors, citation lines, and a year-by-year histogram, no JavaScript involved. Building a PubMed scraper is mostly about picking the right route from four; this page scores each one with output from an October 29, 2026 run.

The ground rules

PubMed is a public literature database run by the US National Library of Medicine, and its robots.txt is unusually legible. Content pages are allowed with a Crawl-delay of 1. The disallow list targets machine surfaces: /api, /rss, /ajax/, export endpoints, saved-search and collection pages, and the /similar, /citedby, /references, and /citations subpages. Search result pages and abstract pages are not on it. My reading is that one well-paced fetch of a public page matches the site’s stated preferences, while bulk belongs in E-utilities, the official API. That is a map, not legal advice; Is Web Scraping Legal? is the plain-English version.

Everything below ran from a home connection using plain curl and Magpie v0.1.32, a local Go scraper (github.com/motherlodelab/magpie). Sites change, so re-verify any number you build a pipeline on.

What a PubMed scraper is working with

The homepage headlines more than 40 million citations. A search for remdesivir returns 4,992 results, 10 per page, in one static HTML response of 252,904 bytes. The default sort is Best Match, and &sort=date reorders server-side with no JavaScript.

What the pages do not have is any schema.org markup. I grepped both a search page and an abstract page for application/ld+json and found zero occurrences, so Magpie’s JSON-LD sidecar comes back empty on every PubMed URL I tried. The structured surface that does exist is a set of Highwire citation_* meta tags on abstract pages: citation_title, citation_authors, citation_date, citation_journal_title, citation_pmid, citation_doi, citation_volume, citation_issue, and citation_issn. Also, the sitemap that robots.txt advertises returns an empty sitemapindex. You cannot crawl PubMed by sitemap; the site expects you to search.

Scrape PubMed search results

The one-command route:

magpie scrape "https://pubmed.ncbi.nlm.nih.gov/?term=remdesivir" > results.json

The clean markdown keeps almost everything a search page offers. The results-by-year graphic arrives as a real table, one row per year. Each hit keeps its linked title, author string, journal citation with PMID, and status flags like “Free PMC article” and “Review”. The match count sits in the text, so grep "4,992" tells you whether the corpus moved since yesterday. One quirk: each result’s snippet appears twice, because PubMed renders two snippet variants in the page and the cleaner keeps both. Abridged sample:

### 4,992 results

[**Remdesivir**.](https://pubmed.ncbi.nlm.nih.gov/37061276/)

Bakheit AH, et al. Profiles Drug Subst Excip Relat Methodol. 2023;48:71-108.
PMID: 37061276 Free PMC article. Review.

For titles, authors, and PMIDs, that markdown is enough. It is not enough for abstracts, which is what the next two routes fix.

Two behavior notes before you paginate. First, &page=2 works as a plain static fetch when you pace yourself; my paced run pulled 253,130 bytes and 10 fresh results. Second, and this is the trap: PubMed serves an intermittent reCAPTCHA “Checking your browser” interstitial under fast pacing. I hit it twice in eight requests spaced 1.5 to 3 seconds apart, and then never again once I moved to roughly 4-second spacing. It is not a hard block. The page title changes, the result count drops to zero, and a retry after a pause gets the real page. Build retry on title-or-count checks, and do not hammer. Dead PMIDs behave differently: PubMed answers a nonexistent record with HTTP 203 rather than 404, and Magpie’s quality gate reports quality blocked (access-denied) and exits 8. Treat exit 8 plus a 203 as “record does not exist”, not “site is down”.

Scrape the abstract page

Abstract pages are where the real content lives, and they clean beautifully. I pointed Magpie at PMID 32678530, the RECOVERY trial’s dexamethasone paper, mostly because its record links to a ClinicalTrials.gov registry entry, the NCT04381936 you can see in the abstract itself:

magpie scrape "https://pubmed.ncbi.nlm.nih.gov/32678530/" > abstract.json

The result is 1,020 words of clean markdown: the full labeled abstract with its Background, Methods, Results, and Conclusions sections, 26 hyperlinked author names, the PMID, the PMCID, the DOI, a five-item references preview, “Comment in” links, the Grants and funding list, and LinkOut resources. Magpie has no PubMed-specific extractor among its 27 verticals; this is the generic fetch, clean, extract pipeline doing its normal job on cooperative markup.

Three things get dropped from that markdown: the affiliation strings, the Keywords list, and the MeSH terms. They exist in the page, as keywords-list and mesh-terms elements, but they sit in collapsed markup the cleaner discards. If you need them, ask for the cleaned document instead:

magpie scrape "https://pubmed.ncbi.nlm.nih.gov/32678530/" --page-format html

I verified the output keeps the full multi-institution affiliation paragraph and the MeSH section that the default markdown omits. Parse it with your usual HTML tool and you have everything the page knows.

The format=pubmed toggle: MEDLINE records without an API call

This is the route the SERP never mentions. Append &format=pubmed to a search URL and the site swaps result cards for complete MEDLINE records inside a <pre> block: title (TI -), abstract (AB -), affiliations (AD -), MeSH headings (MH -), author keywords (OT -), publication dates, and DOI. One request, 64,875 bytes, ten full records. The same toggle works on an abstract page, where the <pre> carries that record’s complete MEDLINE entry.

magpie scrape "https://pubmed.ncbi.nlm.nih.gov/?term=remdesivir&format=pubmed" \
  --page-format raw > records.txt

Magpie’s default markdown on this URL returns 32,001 characters but collapses the record’s newlines, so records run together in one paragraph. With --page-format raw the body is untouched and each record starts at a PMID- line (nine of ten sat at column zero in my capture; one wrapped). Split on PMID- and each record parses with a dozen lines of string handling.

One honesty note: this is a display format of an allowed page, not a documented machine interface. For a nightly one-page pull it is a fair deal for the site. For sustained bulk, the API is the route NLM actually asks you to use.

E-utilities: the official API, and when it wins

E-utilities is free, keyless at the basic tier, and boring in the best way. Two calls cover PubMed:

# IDs for a search
curl -s "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=remdesivir&retmax=200"
# full records for those IDs, plain text
curl -s "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&id=32678530&rettype=abstract&retmode=text"

The count parity is exact: esearch reported Count 4,992 for the same query the web UI shows as 4,992 results. Ordering is not parity. esearch returns its default order, and I verified its first three PMIDs match the web UI’s &sort=date order exactly (42950394, 42943336, 42937280), not the default Best Match order. If position matters to you, sort explicitly wherever you are.

efetch with retmode=xml gives typed fields; the dexamethasone record carries 20 MeshHeading elements, plus abstract, affiliations, and publication types, with no HTML parsing anywhere. The documented rate policy is 3 requests per second without a key and 10 with a free API key, and NCBI does enforce it. For anything past a few thousand records, the API beats every page route: stable contract, machine formats, no challenge interstitials, and you stop caring what the HTML looks like. Python teams usually reach this same place through Biopython’s Entrez wrapper, the standard answer in every tutorial; the no-code route is a PubMed template on Apify or Thunderbit. What neither the tutorials nor the templates tell you is what the site does under fast pacing, which is the part that actually breaks scripts. For full article text rather than abstracts, PubMed Central has its own Open Access subset and bulk routes, which is a different doorway to the same library.

Which route, when

You need Route
Titles, authors, PMIDs from a search magpie scrape on the search URL
One abstract, human-readable magpie scrape on the abstract URL
Affiliations or MeSH from one record Same URL with --page-format html
Ten records with abstracts, one request &format=pubmed, parse the <pre>
Thousands of records, typed fields esearch + efetch, 3 req/s or 10 with key
New results over time magpie watch on a &sort=date search URL

Scaling politely

Magpie’s crawl command reads robots.txt and honors the Crawl-delay of 1, which makes it the safe default for walking result pages; a single scrape is a user-directed fetch and does not consult robots, so your pacing is your policy there. In my runs, requests spaced around 4 seconds never saw a challenge, and faster sequences did. Magpie’s batch mode has --concurrency but no per-host delay, so keep concurrency at 1 for PubMed and sleep between calls. If you want an alert when a search turns up something new, watch the &sort=date URL: Magpie hashes the page and reports a word-diff on any change. The first result’s PMID is the signal you care about, but the result count moves when records get indexed too, so read the diff before you act.

FAQ

Is it legal to scrape PubMed? The database is a US government-run public resource, and robots.txt permits content pages to crawlers at a 1-second crawl delay while steering bulk users to E-utilities. Journal abstracts carry publisher copyrights. This is a layout of the rules, not legal advice.

Does PubMed have an official API? Yes: E-utilities, free, no key required. esearch.fcgi returns IDs for a query, efetch.fcgi returns full records as text or XML. The documented rate limits are 3 requests per second keyless and 10 with a free API key.

How do I download abstracts in bulk? Loop esearch with retmax to collect PMIDs, then efetch them in ID batches. For article full text rather than abstracts, use PubMed Central’s Open Access subset and its bulk download routes instead of PubMed pages.

Why does my scraper get a CAPTCHA on PubMed? Pacing. I hit reCAPTCHA interstitials on roughly 1-in-4 requests at 2 to 3 second spacing and never at 4-second spacing. It is intermittent, so retry after a pause and check the page title before parsing. Sustained abuse gets you blocked properly.

Does Magpie need an API key for PubMed? No. Magpie scrapes the public pages directly with no key and no account, and its LLM features are bring-your-own-key only. For bulk record pulls I would still use E-utilities; Magpie’s page pipeline is for searches and individual abstracts.

The first command to run

If you came for one paper, run the abstract one-liner above and read the markdown. If you came for a corpus, start with esearch and retmax=200, because a 15 KB XML response beats ten HTML pages and carries the MeSH terms the clean markdown drops. And if you want the most underpriced trick on this page, append &format=pubmed to your search URL once and look at what ten records cost you: one request. More site guides live at Scrapers for Popular Websites, including the arXiv scraper for preprints that PubMed does not index.

Stop renting credits.

One flat price, your machine, your keys.

Download free for Windows, macOS and Linux

Windows · macOS · Linux $49/mo flat, cancel anytime