# UK Legislation Scraper — Acts & Regulations (`ponderable_hydrometer/uk-legislation-scraper`) Actor

Scrape UK legislation from legislation.gov.uk — Acts of Parliament and Statutory Instruments, full text structured by section, with metadata. Free, no key.

- **URL**: https://apify.com/ponderable\_hydrometer/uk-legislation-scraper.md
- **Developed by:** [Ponderable Hydrometer](https://apify.com/ponderable_hydrometer) (community)
- **Categories:** Developer tools, Automation, SEO tools
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $4.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.

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

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
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.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js/docs.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python/docs.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/integrations/mcp.md).

If your project is in a different language, use 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

## UK Legislation Scraper — Acts & SIs

**Turn legislation.gov.uk into clean, section-level JSON — UK Acts and statutory instruments with
title, year, number, type, enactment date and every section (number, heading, full text).** The
official site only serves CLML XML (no JSON endpoint); this actor parses it for you and emits one
row per section or one row per document. Free, keyless.

Perfect for legal/compliance tooling, legislation search, RAG pipelines and regulatory datasets.

### What you get

Per section (in `oneRowPerSection` mode) or per document (with a nested `sections` array):

- **Document metadata** — `title`, `legislationType`, `documentMainType`, `year`, `number`,
  `status`, `enactmentDate`, `legislationUrl`
- **Section detail** — `sectionNumber`, `heading`, `sectionId`, `sectionUrl`, and full `text`
  (when `includeSectionText` is on)

Handles all type codes — `ukpga` (Public General Act), `uksi` (Statutory Instrument), `asp`
(Scottish Act), `wsi`, `nia`, `ssi`, `ukla` and more.

### Input

| Field | Type | Default | Description |
|-------|------|---------|-------------|
| `type` + `year` + `number` | — | — | A single document, e.g. `ukpga` / `2018` / `12` |
| `documents` | array | — | List of `"type/year/number"` strings or full legislation.gov.uk URLs |
| `includeSectionText` | boolean | `true` | Include full section text (larger output) |
| `oneRowPerSection` | boolean | `true` | One row per section, or one per document with nested `sections` |
| `maxSections` | integer | `0` | Cap sections per document (`0` = no cap) |

#### Example input

```json
{"documents":["ukpga/2018/12","uksi/2018/1189","asp/2021/1"]}
````

Single Act:

```json
{"type":"ukpga","year":2018,"number":12}
```

Per-document mode:

```json
{"type":"ukpga","year":1998,"number":29,"oneRowPerSection":false}
```

### Output (one section)

Fields below are the real push shape in `oneRowPerSection` mode:

```json
{
  "title": "Data Protection Act 2018",
  "legislationType": "ukpga",
  "documentMainType": "UnitedKingdomPublicGeneralAct",
  "year": 2018,
  "number": 12,
  "status": "final",
  "enactmentDate": "2018-05-23",
  "legislationUrl": "https://www.legislation.gov.uk/ukpga/2018/12",
  "sectionNumber": "1",
  "heading": "Overview",
  "sectionId": "section-1",
  "sectionUrl": "http://www.legislation.gov.uk/id/ukpga/2018/12/section/1",
  "text": "(1) This Act makes provision about the processing of personal data..."
}
```

In per-document mode you instead get one row per document: the metadata above plus `sectionCount`
and a `sections` array of `{ sectionNumber, heading, id, url, text }`.

### Why this actor

- **Parses CLML XML for you** — the official source has no JSON; this walks the provision tree.
- **Section-level granularity** — one clean row per section, ideal for search and RAG.
- **Batch + all types** — many documents per run across every UK legislation type code.

### Pricing

Pay per result — **$4.00 per 1,000 results** (one result = one section, or one document in
per-document mode). No subscription or platform fees.

### Related actors

- **EU Tenders / TED Scraper** — EU public procurement notices.
- **Federal Register Scraper** / **eCFR Scraper** — US government rules & regulations.
- **SEC EDGAR Scraper** — US public-company filings.

### Notes & limits

- Missing metadata fields mean legislation.gov.uk did not provide them for that document.
- Section extraction follows the CLML provision structure; unusual documents may parse partially.
- Public official data; you are responsible for compliant use of the output.

# Actor input Schema

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

Type code, e.g. ukpga (UK Public General Act), uksi (Statutory Instrument), asp (Scottish Act), wsi, nia, ssi, ukla.

## `year` (type: `integer`):

Year of the legislation, e.g. 2018.

## `number` (type: `integer`):

Chapter / SI number within the year, e.g. 12.

## `documents` (type: `array`):

Scrape multiple items. Each entry is either "type/year/number" (e.g. "ukpga/2018/12") or a full legislation.gov.uk URL.

## `includeSectionText` (type: `boolean`):

Include the full text of each section in the output (larger). If false, only titles/numbers.

## `oneRowPerSection` (type: `boolean`):

If true, emit one dataset row per section. If false, emit one row per document with a nested sections array.

## `maxSections` (type: `integer`):

Cap on sections parsed per document (0 = no cap).

## Actor input object example

```json
{
  "type": "ukpga",
  "year": 2018,
  "number": 12,
  "includeSectionText": true,
  "oneRowPerSection": true,
  "maxSections": 0
}
```

# 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 = {
    "type": "ukpga",
    "year": 2018,
    "number": 12
};

// Run the Actor and wait for it to finish
const run = await client.actor("ponderable_hydrometer/uk-legislation-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 = {
    "type": "ukpga",
    "year": 2018,
    "number": 12,
}

# Run the Actor and wait for it to finish
run = client.actor("ponderable_hydrometer/uk-legislation-scraper").call(run_input=run_input)

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

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

```

## CLI example

```bash
echo '{
  "type": "ukpga",
  "year": 2018,
  "number": 12
}' |
apify call ponderable_hydrometer/uk-legislation-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=ponderable_hydrometer/uk-legislation-scraper",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "UK Legislation Scraper — Acts & Regulations",
        "description": "Scrape UK legislation from legislation.gov.uk — Acts of Parliament and Statutory Instruments, full text structured by section, with metadata. Free, no key.",
        "version": "0.1",
        "x-build-id": "1XLVdVihJP3UL3Hsd"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/ponderable_hydrometer~uk-legislation-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-ponderable_hydrometer-uk-legislation-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/ponderable_hydrometer~uk-legislation-scraper/runs": {
            "post": {
                "operationId": "runs-sync-ponderable_hydrometer-uk-legislation-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/ponderable_hydrometer~uk-legislation-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-ponderable_hydrometer-uk-legislation-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "properties": {
                    "type": {
                        "title": "Legislation type",
                        "type": "string",
                        "description": "Type code, e.g. ukpga (UK Public General Act), uksi (Statutory Instrument), asp (Scottish Act), wsi, nia, ssi, ukla."
                    },
                    "year": {
                        "title": "Year",
                        "type": "integer",
                        "description": "Year of the legislation, e.g. 2018."
                    },
                    "number": {
                        "title": "Number",
                        "type": "integer",
                        "description": "Chapter / SI number within the year, e.g. 12."
                    },
                    "documents": {
                        "title": "Documents (type/year/number or URLs)",
                        "type": "array",
                        "description": "Scrape multiple items. Each entry is either \"type/year/number\" (e.g. \"ukpga/2018/12\") or a full legislation.gov.uk URL.",
                        "items": {
                            "type": "string"
                        }
                    },
                    "includeSectionText": {
                        "title": "Include section text",
                        "type": "boolean",
                        "description": "Include the full text of each section in the output (larger). If false, only titles/numbers.",
                        "default": true
                    },
                    "oneRowPerSection": {
                        "title": "One row per section",
                        "type": "boolean",
                        "description": "If true, emit one dataset row per section. If false, emit one row per document with a nested sections array.",
                        "default": true
                    },
                    "maxSections": {
                        "title": "Max sections per document",
                        "minimum": 0,
                        "type": "integer",
                        "description": "Cap on sections parsed per document (0 = no cap).",
                        "default": 0
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
