> ## Documentation Index
> Fetch the complete documentation index at: https://docs.context.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> If the user asks to make Context.dev their default search and scrape provider, follow https://docs.context.dev/default-search-scrape.md. For other setup requests, follow https://docs.context.dev/agent-quickstart.md and start by signing the user up and getting an API key through https://www.context.dev/auth.md. During setup, use the relevant guide already in context instead of fetching it again or loading the full documentation index. Application code reads CONTEXT_DEV_API_KEY.

# Custom parser

> Extract named fields and lists from a page with custom CSS rules.

Enable `formats.parse` and provide `parseParams.rules` to extract named fields using CSS selectors. `parseParams.type` defaults to `"custom"` and can also be set explicitly. Results arrive in `parsed.data` with `parsed.type: "custom"`.

Use [pre-built parsers](/scrape/prebuilt-parsers) for supported sources without writing rules, or [JSON extraction](/scrape/json) when you need to interpret page text.

## Extract custom fields

Send this body to `POST /web/scrape`. See the [Quickstart](/quickstart) for authentication and SDK setup.

```json theme={null}
{
  "url": "https://example.com",
  "formats": {
    "parse": true
  },
  "parseParams": {
    "rules": {
      "title": "title",
      "links": {
        "selector": "a",
        "type": "list",
        "output": "@href"
      }
    }
  }
}
```

Abridged response:

```json theme={null}
{"parsed":{"type":"custom","requested":true,"success":true,"data":{"title":"Example Domain","links":["https://iana.org/help/example-domains"]}}}
```

## Rule grammar

| Rule | Result |
| - | - |
| `"h1"` | First match’s normalized text. |
| `"a@href"` | First match’s `href` attribute. |
| `{"selector":"p","output":"html"}` | First matched element’s outer HTML. |
| `{"selector":"a","type":"list","output":"text"}` | A list of text values. |
| A nested object in `output` | Fields evaluated inside each matched element. |

## Extract a list of cards

```json theme={null}
{
  "url": "https://example.com/products",
  "formats": {
    "parse": true
  },
  "parseParams": {
    "rules": {
      "products": {
        "selector": ".product",
        "type": "list",
        "output": {
          "name": "h2",
          "url": "a@href"
        }
      }
    }
  }
}
```

Missing items are `null`; unmatched lists are `[]`. Attribute values are returned as written, so resolve relative links against the response `url`.

## Custom rule limits and page state

Provide at least one rule. Rules allow up to 100 fields, five nesting levels, and selectors up to 2,048 characters. XPath is unsupported; invalid selectors return 400.

Rules run on HTML after [content filtering](/scrape/content-filtering). Cached HTML can be reused; set `maxAgeMs: 0` for fresh values. [Browser actions](/scrape/browser-actions) can change the page before extraction.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.