# PubMed Search Scraper (`searchapi/pubmed-search-scraper`) Actor

Fetch biomedical articles from NCBI PubMed using the public E-utilities API.

- **URL**: https://apify.com/searchapi/pubmed-search-scraper.md
- **Developed by:** [Search API](https://apify.com/searchapi) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.99 / 1,000 search results

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## PubMed Search Scraper

### What does PubMed Search Scraper do?

PubMed Search Scraper collects biomedical literature metadata from **NCBI PubMed** using only public endpoints.\
You can search by keyword, constrain by date range, apply publication-type filters, and download a structured dataset with article titles, authors, journal information, abstracts, DOI, keywords, and MeSH terms.

Only normalized articles are written to the dataset. Empty searches and bounded request failures are recorded in the fixed `run-summary` key-value record, so API consumers never receive diagnostic placeholders as article rows.

This Actor is built for API-first, deterministic extraction:

- it uses PubMed E-utilities (`esearch`, `esummary`, `efetch`)
- runs with bounded retries and backoff
- validates HTTP status, content type, payload size, and JSON/XML shape before parsing
- filters and normalizes outputs
- deduplicates article IDs
- returns stable fields with real URLs, IDs, and timestamps

### Why use PubMed Search Scraper?

It is useful for:

- literature review pipelines
- research intelligence and grant preparation
- data collection for bibliographic analysis
- tracking publication trends for a query
- rapid extraction of titles + abstracts for downstream NLP

### How to use PubMed Search Scraper

1. Open the actor and paste input in the **Input** tab.
2. Set a query, for example `machine learning`.
3. Set limits (`maxResults`, `pageSize`, `maxPages`) to control runtime.
4. Optionally set `dateFrom`, `dateTo`, and `articleType`.
5. Enable/disable optional enrichment fields.
6. Run the actor locally with `apify run --purge` or on cloud.

Example input:

```json
{
  "query": "machine learning",
  "maxResults": 20,
  "pageSize": 25,
  "maxPages": 4,
  "sortBy": "pub_date",
  "dateFrom": "2025-01-01",
  "dateTo": "2026-12-31",
  "articleType": "Journal Article, Randomized Controlled Trial",
  "includeAbstract": true,
  "includeAuthors": true,
  "includeMeSH": true,
  "includeKeywords": true,
  "requestDelayMs": 250,
  "maxConcurrent": 3,
  "maxRequestRetries": 2,
  "requestTimeoutSecs": 25
}
```

### Output

Each output item is a normalized article object with a stable identity.

```json
{
  "recordType": "article",
  "found": true,
  "dataAvailable": true,
  "pmid": "12345678",
  "doi": "10.1000/example-doi",
  "title": "Example biomedical article title",
  "journal": "Example Journal of Medicine",
  "publicationDate": "2026-01-15T00:00:00.000Z",
  "authors": [
    { "name": "Alex Example", "initials": "A.E." }
  ],
  "abstract": "This example abstract summarizes a biomedical research finding.",
  "meshTerms": ["Machine Learning", "Biomedical Research"],
  "keywords": ["machine learning"],
  "sourceUrl": "https://pubmed.ncbi.nlm.nih.gov/12345678/",
  "scrapedAt": "2026-01-15T12:00:00.000Z"
}
```

If the public endpoint returns no matches, the dataset is empty and the separate summary looks like this:

```json
{
  "recordType": "pubmed-run-summary",
  "recordsStored": 0,
  "noResults": true,
  "runStatus": "NO_RESULTS",
  "errorCode": "no_matches"
}
```

You can download the dataset in various formats such as JSON, HTML, CSV, or Excel directly from Apify. The fixed `run-summary` key records the requested query, generated PubMed search term, sort/date/type filters, pages fetched, exact record count, and final status.

### Data table

| Field | Description |
| --- | --- |
| `pmid` | PubMed Identifier used as a stable identity |
| `doi` | DOI when available |
| `title` | Article title |
| `journal` | Journal title |
| `publicationDate` | Parsed publication date |
| `authors` | Normalized author objects |
| `abstract` | Short text excerpt of abstract |
| `meshTerms` | MeSH descriptors |
| `keywords` | Author keywords |
| `sourceUrl` | PubMed canonical URL |
| `scrapedAt` | Run timestamp |

### Pricing / cost estimation

This actor uses public NCBI endpoints and is ideal for small-to-medium literature sweeps.
If your run is large, reduce `maxResults` / increase delays to reduce request pressure.
For high-volume use, NCBI API keys can increase request limits and reduce throttling risk.

### Tips and advanced options

- Use a narrow `query` and short date window to keep results manageable.
- Keep `maxConcurrent` lower if you encounter transient API throttling.
- Use `articleType` to narrow to specific publication types.
- Keep `requestDelayMs` above 100 ms when running frequently.
- For reproducibility, log each input used and persist the resulting `run-summary` record.

### FAQ, disclaimers, and support

- PubMed content and availability can change over time; re-run for fresh data.
- `publicationDate` and abstracts are best-effort normalized from API payloads.
- This actor uses publicly documented NCBI endpoints and avoids bypassing paywalls or private controls.
- For custom feature requests, use the actor issue/reporting channel.

# Actor input Schema

## `query` (type: `string`):

Keyword query passed to PubMed search endpoint.

## `maxResults` (type: `integer`):

Maximum article records returned across all pages.

## `pageSize` (type: `integer`):

Number of search IDs fetched per page.

## `maxPages` (type: `integer`):

Hard bound on how many search pages are scanned.

## `sortBy` (type: `string`):

PubMed sort order for search results.

## `dateFrom` (type: `string`):

Filter from publication date (YYYY-MM-DD). Leave empty for no lower bound.

## `dateTo` (type: `string`):

Filter to publication date (YYYY-MM-DD). Leave empty for no upper bound.

## `articleType` (type: `string`):

Comma-separated PubMed publication types, e.g. "Journal Article, Clinical Trial, Meta-Analysis".

## `includeAbstract` (type: `boolean`):

Load article abstracts from EFetch XML payload.

## `includeAuthors` (type: `boolean`):

Extract author names and affiliations when available.

## `includeMeSH` (type: `boolean`):

Extract MeSH descriptors when available.

## `includeKeywords` (type: `boolean`):

Extract author keywords when available.

## `requestDelayMs` (type: `integer`):

Respectful delay between HTTP calls.

## `maxConcurrent` (type: `integer`):

Concurrency cap for PubMed details requests.

## `maxRequestRetries` (type: `integer`):

Retries for temporary network errors, rate limits, timeouts, and 5xx responses.

## `requestTimeoutSecs` (type: `integer`):

Bounded timeout for each NCBI API request.

## `ncbiApiKey` (type: `string`):

Optional API key for higher rate limits (use a valid NCBI API key).

## Actor input object example

```json
{
  "query": "machine learning",
  "maxResults": 20,
  "pageSize": 25,
  "maxPages": 4,
  "sortBy": "relevance",
  "includeAbstract": true,
  "includeAuthors": true,
  "includeMeSH": true,
  "includeKeywords": true,
  "requestDelayMs": 250,
  "maxConcurrent": 3,
  "maxRequestRetries": 2,
  "requestTimeoutSecs": 25
}
```

# Actor output Schema

## `dataset` (type: `string`):

Dataset containing complete article records and bounded diagnostic rows.

## `summary` (type: `string`):

Fixed run-summary JSON record with success and diagnostic counts.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("searchapi/pubmed-search-scraper").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("searchapi/pubmed-search-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call searchapi/pubmed-search-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,searchapi/pubmed-search-scraper"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/IJzD8ZBVjRne9eSV0/builds/NI9oF3FQVl1Ak2Zvv/openapi.json
