> 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/pt-br/web-scraper-api/features/custom-parser/generating-parsing-instructions-via-api.md).

# Gerando instruções de parsing via API

Você pode gerar conjuntos de instruções de parsing via API fornecendo URLs e descrevendo quais pontos de dados você gostaria de fazer parsing. Ao receber as instruções de parsing geradas, você pode salvá-las como um [predefinição de parser](/products/pt-br/web-scraper-api/features/custom-parser/parser-presets.md) ou simplesmente enviar as instruções com sua solicitação de scraping.

Você também pode gerar instruções de parsing via [OxyCopilot](/products/pt-br/web-scraper-api/web-scraper-api-playground/oxycopilot.md) no nosso Web Scraper API Playground.

## Gerar instruções a partir do prompt

Você pode gerar instruções de parsing inserindo uma descrição em texto livre dos pontos de dados que você gostaria de fazer parsing e nos fornecendo algumas URLs que pertençam ao mesmo tipo de página. A API responderá com um conjunto de instruções de parsing.

* **Endpoint**: `https://data.oxylabs.io/v1/parsers/generate-instructions/prompt`
* **Método**: `POST`
* **Autenticação**: `Básico`
* **Cabeçalhos da solicitação**: `Content-Type: application/json`

### Payload de exemplo

```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>Descrição</th></tr></thead><tbody><tr><td><mark style="background-color:green;"><strong><code>prompt_text</code></strong></mark></td><td>Descrição em texto livre dos pontos de dados a serem analisados.</td></tr><tr><td><mark style="background-color:green;"><strong><code>urls</code></strong></mark></td><td>Lista de URLs que exemplificam o tipo de página para o qual você gostaria de obter instruções de parsing. Recomendamos fornecer 3 a 5 URLs para ajudar o parser a se adaptar a diferentes layouts e melhorar a precisão do parsing.</td></tr><tr><td><code>render</code></td><td>Se a renderização de JS deve ser usada para buscar o conteúdo necessário.</td></tr></tbody></table>

\- parâmetro obrigatório

### Resposta de exemplo

```json
{
    "parsing_instructions": {
        "developer_name": {
            "_fns": [
                {
                    "_args": [
                        "//div[contains(@class, 'brand-wrapper')]//span[@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"
                }
            ]
        },
        "title": {
            "_fns": [
                {
                    "_args": [
                        "//div[contains(@class, 'product-info-wrapper')]//h2/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"
    }
}
```

## Gerar instruções a partir do schema JSON

Há casos em que você deseja obter dados analisados em um schema JSON específico. Você pode usar este endpoint para obter instruções de parsing que aderem estritamente ao schema que você fornecer.

* **Endpoint**: `https://data.oxylabs.io/v1/parsers/generate-instructions/schema`
* **Método**: `POST`
* **Autenticação**: `Básico`
* **Cabeçalhos da solicitação**: `Content-Type: application/json`

### Payload de exemplo

```json
{
  "urls": [
    "https://oxylabs.io",
    "https://example.com",
    "https://bbc.co.uk"
  ],
  "prompt_schema": {
    "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>Descrição</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/">schema JSON</a> descrevendo a saída necessária do parser.</td></tr><tr><td><mark style="background-color:green;"><strong><code>urls</code></strong></mark></td><td>Lista de URLs que exemplificam o tipo de página para o qual você gostaria de obter instruções de parsing.</td></tr><tr><td><code>render</code></td><td>Se a renderização de JS deve ser usada para buscar o conteúdo necessário.</td></tr></tbody></table>

\- parâmetro obrigatório

### Resposta de exemplo

```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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
