> For the complete documentation index, see [llms.txt](https://developers.oxylabs.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.oxylabs.io/products/es/web-scraper-api/features/custom-parser/generating-parsing-instructions-via-api.md). Agents can also search and read this documentation through its [MCP server](https://developers.oxylabs.io/~gitbook/mcp).

# Generación de instrucciones de análisis mediante API

Mira cómo puedes generar parsers automáticamente enviando solicitudes a la API.

Puede generar conjuntos de instrucciones de análisis mediante API proporcionando URLs y describiendo qué puntos de datos le gustaría analizar. Al recibir las instrucciones de análisis generadas, puede guardarlas como una [preajuste de parser](https://developers.oxylabs.io/products/es/web-scraper-api/features/custom-parser/parser-presets.md) o simplemente enviar las instrucciones con su solicitud de scraping.

También puede generar instrucciones de análisis a través de [OxyCopilot](https://developers.oxylabs.io/products/es/web-scraper-api/web-scraper-api-playground/oxycopilot.md) en nuestro Web Scraper API Playground.

## Generar instrucciones a partir de un prompt

Puede generar instrucciones de análisis introduciendo una descripción en texto libre de los puntos de datos que le gustaría analizar y dándonos algunas URLs que pertenezcan al mismo tipo de página. La API responderá con un conjunto de instrucciones de análisis.

* **Endpoint**: `https://data.oxylabs.io/v1/parsers/generate-instructions/prompt`
* **Método**: `POST`
* **Autenticación**: `Básico`
* **Encabezados de la solicitud**: `Content-Type: application/json`

### Carga de ejemplo

```json
{ 
  "prompt_text": "Parse title of the product, main price, developer name and platform name.",
  "urls": [
    "https://sandbox.oxylabs.io/products/1",
    "https://sandbox.oxylabs.io/products/2",
    "https://sandbox.oxylabs.io/products/4"
  ],
  "render": false
}
```

<table><thead><tr><th width="177.1328125">Parámetro</th><th>Descripción</th></tr></thead><tbody><tr><td><mark style="background-color:green;"><strong><code>prompt_text</code></strong></mark></td><td>Descripción en texto libre de los puntos de datos que se analizarán.</td></tr><tr><td><mark style="background-color:green;"><strong><code>urls</code></strong></mark></td><td>Lista de URLs que ejemplifican el tipo de página para el que desea obtener instrucciones de análisis. La API acepta hasta 5 URLs. Recomendamos proporcionar 3-5 URLs para ayudar al parser a adaptarse a diferentes diseños y mejorar la precisión del análisis.</td></tr><tr><td><code>render</code></td><td>Indica si se debe usar renderizado de JS para obtener el contenido requerido.</td></tr></tbody></table>

\- parámetro obligatorio

### Respuesta de ejemplo

```json
{
    "parsing_instructions": {
        "developer_name": {
            "_fns": [
                {
                    "_args": [
                        "//div[contains(@class, 'brand-wrapper')]//span[contains(@class, 'brand developer')]"
                    ],
                    "_fn": "xpath"
                },
                {
                    "_args": [
                        "normalize-space(.)"
                    ],
                    "_fn": "xpath"
                },
                {
                    "_args": " ",
                    "_fn": "join"
                }
            ]
        },
        "main_price": {
            "_fns": [
                {
                    "_args": [
                        "//div[contains(@class, 'product-info-wrapper')]//div[contains(@class, 'price')]/text()"
                    ],
                    "_fn": "xpath_one"
                },
                {
                    "_fn": "amount_from_string"
                }
            ]
        },
        "platform_name": {
            "_fns": [
                {
                    "_args": [
                        "//span[contains(@class, 'game-platforms-wrapper')]",
                        "//div[contains(@class, 'brand-wrapper')]//span[contains(@class, 'game-platforms-wrapper')]"
                    ],
                    "_fn": "xpath"
                },
                {
                    "_args": [
                        "normalize-space(.)"
                    ],
                    "_fn": "xpath"
                },
                {
                    "_args": " ",
                    "_fn": "join"
                }
            ]
        },
        "title": {
            "_fns": [
                {
                    "_args": [
                        "//div[contains(@class, 'product-info-wrapper')]//h2/text()",
                        "//div[contains(@class, 'product-info-wrapper')]//h2[contains(@class, 'title')]/text()"
                    ],
                    "_fn": "xpath_one"
                },
                {
                    "_args": [
                        "^\\s*(.[\\s\\S]*?)\\s*$",
                        1
                    ],
                    "_fn": "regex_search"
                }
            ]
        }
    },
    "prompt_schema": {
        "properties": {
            "developer_name": {
                "description": "Developer name.",
                "title": "Developer Name",
                "type": "string"
            },
            "main_price": {
                "description": "Main price of the product.",
                "title": "Main Price",
                "type": "number"
            },
            "platform_name": {
                "description": "Platform name.",
                "title": "Platform Name",
                "type": "string"
            },
            "title": {
                "description": "Title of the product.",
                "title": "Title",
                "type": "string"
            }
        },
        "required": [
            "title",
            "main_price",
            "developer_name",
            "platform_name"
        ],
        "title": "Fields",
        "type": "object"
    }
}
```

## Generar instrucciones a partir de un esquema JSON

Hay casos en los que desea obtener datos analizados en un esquema JSON específico. Puede usar este endpoint para obtener instrucciones de análisis que se ajusten estrictamente al esquema que proporcione.

* **Endpoint**: `https://data.oxylabs.io/v1/parsers/generate-instructions/schema`
* **Método**: `POST`
* **Autenticación**: `Básico`
* **Encabezados de la solicitud**: `Content-Type: application/json`

### Carga de ejemplo

```json
{
  "urls": [
    "https://oxylabs.io",
    "https://example.com",
    "https://bbc.co.uk"
  ],
  "prompt_schema": {
    "type": "object",
    "properties": {
      "links": {
        "description": "An array of URL strings",
        "type": "array",
        "items": {
          "type": "string",
          "description": "A URL"
        }
      }
    },
    "required": [
      "links"
    ]
  },
  "render": false
}
```

<table><thead><tr><th width="177.1328125">Parámetro</th><th>Descripción</th></tr></thead><tbody><tr><td><mark style="background-color:green;"><strong><code>prompt_schema</code></strong></mark></td><td><a href="https://json-schema.org/">esquema JSON</a> que describe la salida requerida del parser.</td></tr><tr><td><mark style="background-color:green;"><strong><code>urls</code></strong></mark></td><td>Lista de URLs que ejemplifican el tipo de página para el que desea obtener instrucciones de análisis. La API acepta hasta 5 URLs.</td></tr><tr><td><code>render</code></td><td>Indica si se debe usar renderizado de JS para obtener el contenido requerido.</td></tr></tbody></table>

\- parámetro obligatorio

### Respuesta de ejemplo

```json
{
    "parsing_instructions": {
            "links": {
                "_fns": [
                    {
                        "_args": [
                            "//a[@href and normalize-space(@href) != '']/@href"
                        ],
                        "_fn": "xpath"
                    }
                ]
            }
        }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developers.oxylabs.io/products/es/web-scraper-api/features/custom-parser/generating-parsing-instructions-via-api.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
