# OpenPrescribing NHS Spend Scraper (`parseforge/openprescribing-scraper`) Actor

Scrapes monthly NHS prescribing spend, items, and cost per item from OpenPrescribing by drug name or BNF code. Returns one flat row per drug per month.

- **URL**: https://apify.com/parseforge/openprescribing-scraper.md
- **Developed by:** [ParseForge](https://apify.com/parseforge) (community)
- **Categories:** Developer tools, Other
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $9.00 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

[![ParseForge](https://raw.githubusercontent.com/ParseForge/apify-assets/main/banner.jpg)](https://apify.com/parseforge?fpr=vmoqkp)

### OpenPrescribing NHS Spend Scraper

**Scrape NHS prescribing spend data from OpenPrescribing by drug name or BNF code.** Get monthly spend, items, and cost per item for every chemical, practice, or CCG. No API key. Export to CSV, JSON, Excel, or XML.

OpenPrescribing publishes monthly NHS prescribing data, but the website has no bulk export and the official NHSBSA files are huge and hard to filter. This Actor reads the public OpenPrescribing pages directly, resolves drug names to BNF chemicals, and returns each drug's monthly spend, items, and cost per item in one flat row. You can search by drug name, pass exact BNF codes, or both.

| Who uses it | What they scrape OpenPrescribing for |
|---|---|
| Pharma market analysts | Track monthly spend and volume for a competitor drug across England |
| NHS commissioners | Monitor prescribing trends for a therapeutic area in their CCG |
| Health economists | Build time series of drug costs for cost-effectiveness models |
| Journalists | Investigate changes in NHS spending on specific medicines |

### What it does

This Actor collects monthly NHS prescribing spend, items, and cost per item for each drug or BNF chemical from OpenPrescribing, and returns each drug-month as one flat row.

- 🔍 **Search by drug name:** type "ibuprofen" or "atorvastatin" and the Actor resolves it to all matching BNF chemicals.
- 🎯 **Exact BNF codes:** pass codes like "0407010H0" for Paracetamol to get that chemical only.
- 📅 **Monthly granularity:** each row is one drug in one month, so you can build time series.
- 📊 **Spend and volume:** returns total spend, number of items, and cost per item for every match.
- 🧩 **Flexible input:** use search terms, BNF codes, or both in the same run.

Results export to CSV, JSON, Excel, or XML, or straight from the API.

### What you can do with OpenPrescribing data

**📈 Track competitor drug spend.**

A pharma analyst runs the Actor monthly for a competitor's brand name and watches spend and items trend across England.

**🩺 Monitor CCG prescribing.**

An NHS commissioner passes a list of BNF codes for high-cost drugs and gets monthly spend to spot outliers.

**💰 Build cost-effectiveness models.**

A health economist scrapes five years of monthly cost per item for a drug class to feed a Markov model.

**📰 Investigate spending changes.**

A journalist searches for a recently launched drug and compares monthly spend before and after a policy change.

### Why choose this scraper

| | What you get |
|---|---|
| **No API key** | OpenPrescribing has no public API, so this Actor reads the pages directly. |
| **Drug name resolution** | Type a common name and get all BNF chemicals, no need to look up codes. |
| **Monthly time series** | Each row is one drug in one month, ready for trend analysis. |
| **Flat schema** | Every record has the same fields, so you can merge runs without cleaning. |

### How it compares

No other Store actor targets OpenPrescribing the same way, so the honest comparison is with the alternatives teams actually weigh.

| | OpenPrescribing NHS Spend Scraper | Build it in-house | By hand |
|---|---|---|---|
| Setup | Run it now, zero config | Days of engineering | None, but hours per pull |
| When OpenPrescribing changes | Maintained for you | You fix it | You re-learn the page |
| Proxies, retries, anti-bot | Built in | Your problem | Browser only |
| Output | Fixed JSON schema, CSV/Excel export | Whatever you build | Copy-paste |
| Cost | Pay per result | Engineering time | Analyst hours |

### Configure the run

Drive the Actor from drug names, exact BNF codes, or both, and set a maximum number of records to keep runs predictable. The Input tab lists every parameter.

A first run with the defaults:

```json
{
 "searchTerms": [
 "atorvastatin"
 ],
 "maxItems": 10
}
```

A larger pull:

```json
{
 "searchTerms": [
 "atorvastatin"
 ],
 "maxItems": 200
}
```

### Pricing

Pay-per-result: **$0.011 per result** collected. You pay only for the results written to your dataset.

| Results collected | Approximate cost |
|---|---|
| 100 results | $1.10 |
| 1,000 results | $11.00 |
| 10,000 results | $110.00 |

New Apify accounts start with $5 in free credit.

### Free users

Free-plan runs return up to 10 results as a preview. [Upgrade your Apify plan](https://console.apify.com/sign-up?fpr=vmoqkp) to collect up to 1,000,000 results per run.

### Run it

1. [Create a free Apify account with $5 in credit](https://console.apify.com/sign-up?fpr=vmoqkp).
2. Open the [OpenPrescribing NHS Spend Scraper](https://apify.com/parseforge/openprescribing-scraper?fpr=vmoqkp).
3. Set your inputs and any filters, then click **Start**.
4. Export the results as CSV, Excel, JSON, or XML from the **Dataset** tab.

Run it programmatically through the [Apify API](https://docs.apify.com/api/v2) (`run-sync-get-dataset-items`) or the [ApifyClient](https://docs.apify.com/api/client/js) for JavaScript and Python.

### Use with AI agents (MCP)

Give an AI agent live access to OpenPrescribing through the Model Context Protocol. Add the Actor to Claude, Cursor, or any MCP client:

```bash
claude mcp add --transport http apify "https://mcp.apify.com/?tools=parseforge/openprescribing-scraper"
```

Then prompt it in plain language to run the scraper and read back the results.

### Troubleshooting

**Why am I getting no results?**

Check that your search term is spelled correctly and is a drug or chemical name used in the NHS. If you passed a BNF code, verify it is a valid chemical code, not a product or presentation code.

**The Actor returned fewer records than I expected.**

OpenPrescribing may not have data for every month for every chemical. Also, if you are on the free plan, the preview is limited to 10 records. Upgrade to a paid plan and set a higher "Maximum records".

**My search term resolved to the wrong drug.**

Drug names can be ambiguous. Use an exact BNF code instead, or refine your search term to the full chemical name.

**The run failed with a timeout.**

Large searches with many chemicals can take time. Reduce the number of search terms or BNF codes, or increase the Actor's timeout in the run settings.

### FAQ

| Question | Answer |
|---|---|
| Do I need an API key or login? | No. The Actor reads public OpenPrescribing pages directly, so no registration or key is required. |
| What is a BNF code? | A BNF code is the NHS's unique identifier for a chemical or product, like "0407010H0" for Paracetamol. You can pass these directly or let the Actor resolve drug names to codes. |
| How do I search by drug name? | Add one or more names to the "Prescribing search terms" field, for example "ibuprofen". The Actor resolves each name to all matching BNF chemicals and scrapes them all. |
| Can I mix search terms and BNF codes? | Yes. Both fields are optional, but at least one is required. If you provide both, the Actor scrapes the union of all resolved chemicals. |
| What does one row in the output represent? | One row is one drug (BNF chemical) in one month, with its total spend, number of items, and cost per item for that month. |
| What time period does the data cover? | OpenPrescribing publishes monthly data from 2010 onwards. The Actor returns whatever months are available for the selected chemicals. |
| Is there a limit on how many records I can scrape? | Free users are limited to 10 records as a preview. Paid users can set "Maximum records" up to 1,000,000. |
| Can I get data for a specific practice or CCG? | This Actor scrapes national-level chemical data. For practice or CCG breakdowns, you would need a different approach or the raw NHSBSA files. |
| What export formats are supported? | You can export the dataset as CSV, JSON, Excel, or XML from the Apify platform. |
| How often should I run this Actor? | OpenPrescribing updates monthly, so a monthly scheduled run is typical. You can also run on demand for ad hoc analysis. |

### Related actors

- [openfda-scraper](https://apify.com/parseforge/openfda-scraper?fpr=vmoqkp): Use this for US FDA drug data, including labels and adverse events, when you need a non-UK source.

Browse the full [ParseForge collection](https://apify.com/parseforge?fpr=vmoqkp) for more scrapers.

🆘 **Need help?** Email parseforge@protonmail.com with your run ID, your input, and what you expected.

⚠️ **Disclaimer.** This Actor is unofficial and is not affiliated with, endorsed by, or sponsored by OpenPrescribing, Bennett Institute for Applied Data Science, University of Oxford. It collects only publicly available data. You are responsible for using the collected data in compliance with the source's terms of service and applicable data-protection laws, including GDPR, CCPA, and PIPL. Do not use it to collect personal data unlawfully.

# Actor input Schema

## `searchTerms` (type: `array`):

Drug or chemical names to search (e.g. "ibuprofen", "atorvastatin"). Each resolves to its NHS BNF chemicals.

## `bnfCodes` (type: `array`):

Exact NHS BNF chemical codes (e.g. "0407010H0" for Paracetamol).

## `maxItems` (type: `integer`):

Free users: limited to 10 items (preview). Paid users: optional, max 1,000,000. Each row is one drug in one month.

## Actor input object example

```json
{
  "searchTerms": [
    "atorvastatin"
  ],
  "maxItems": 10
}
```

# Actor output Schema

## `results` (type: `string`):

No description

# 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 = {
    "searchTerms": [
        "atorvastatin"
    ],
    "maxItems": 10
};

// Run the Actor and wait for it to finish
const run = await client.actor("parseforge/openprescribing-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 = {
    "searchTerms": ["atorvastatin"],
    "maxItems": 10,
}

# Run the Actor and wait for it to finish
run = client.actor("parseforge/openprescribing-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 '{
  "searchTerms": [
    "atorvastatin"
  ],
  "maxItems": 10
}' |
apify call parseforge/openprescribing-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,parseforge/openprescribing-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/puAk2WltOO57d09jT/builds/mnVos53pvtY0Nu8uE/openapi.json
