> For the complete documentation index, see [llms.txt](https://docs.scraperapi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.scraperapi.com/ai-parser/endpoints/parse-a-url.md).

# Parse a URL

Use an existing parser to extract data from a URL

```bash
GET https://aiparser.scraperapi.com/parse/{parser_id}/{version}?api_key=API_KEY&url=URL
```

**Path Parameters**

<table><thead><tr><th width="192.1109619140625">Parameter</th><th width="104.5555419921875">Required</th><th>Description</th></tr></thead><tbody><tr><td><code>parser_id</code></td><td>Yes</td><td>The ID returned when the parser was created</td></tr><tr><td><code>version</code></td><td>No</td><td>Parser version to use. If omitted, the latest is used</td></tr></tbody></table>

**Query Parameters**

<table><thead><tr><th width="239.407470703125"></th><th width="83.814697265625"></th><th></th></tr></thead><tbody><tr><td><code>api_key</code></td><td>Yes</td><td>Your ScraperAPI API Key</td></tr><tr><td><code>url</code></td><td>Yes</td><td>The URL to parse</td></tr><tr><td>Any <a href="/pages/u1uiJWhomIMzqF7f2egv#supported-scraperapi-parameters">supported parameter</a></td><td>No</td><td>Additional ScraperAPI parameters</td></tr></tbody></table>

***

**Example**

{% tabs %}
{% tab title="cURL" %}

```bash
curl --request GET \
  --url "https://aiparser.scraperapi.com/parse/<PARSER_ID>?api_key=API_KEY&url=https://quotes.toscrape.com/page/5/"
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

parser_id = "PARSER_ID"
api_key = "API_KEY"
target_url = "https://quotes.toscrape.com/page/5/"

url = f"https://aiparser.scraperapi.com/parse/{parser_id}"

params = {
    "api_key": api_key,
    "url": target_url
}

response = requests.get(url, params=params)

print(response.status_code)
print(response.text)
```

{% endtab %}

{% tab title="NodeJS" %}

```javascript
const parserId = "PARSER_ID";
const apiKey = "API_KEY";
const targetUrl = "https://quotes.toscrape.com/page/5/";

const url = new URL(`https://aiparser.scraperapi.com/parse/${parserId}`);

url.searchParams.append("api_key", apiKey);
url.searchParams.append("url", targetUrl);

async function run() {
  const response = await fetch(url);

  const data = await response.text();

  console.log(response.status);
  console.log(data);
}

run();
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$parserId = "PARSER_ID";
$apiKey = "API_KEY";
$targetUrl = "https://quotes.toscrape.com/page/5/";

$url = "https://aiparser.scraperapi.com/parse/$parserId" .
       "?api_key=" . urlencode($apiKey) .
       "&url=" . urlencode($targetUrl);

$response = file_get_contents($url);

echo $response;
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'net/http'
require 'uri'

parser_id = "PARSER_ID"
api_key = "API_KEY"
target_url = "https://quotes.toscrape.com/page/5/"

uri = URI("https://aiparser.scraperapi.com/parse/#{parser_id}")

uri.query = URI.encode_www_form(
  api_key: api_key,
  url: target_url
)

response = Net::HTTP.get_response(uri)

print(response.body)
```

{% endtab %}

{% tab title="Java" %}

```java
import java.io.*;
import java.net.*;

public class Main {
    public static void main(String[] args) {
        try {
            String parserId = "PARSER_ID";
            String apiKey = "API_KEY";
            String targetUrl = "https://quotes.toscrape.com/page/5/";

            String query = String.format(
                "api_key=%s&url=%s",
                URLEncoder.encode(apiKey, "UTF-8"),
                URLEncoder.encode(targetUrl, "UTF-8")
            );

            URL url = new URL(
                "https://aiparser.scraperapi.com/parse/" + parserId + "?" + query
            );

            BufferedReader in = new BufferedReader(
                new InputStreamReader(url.openStream())
            );

            StringBuilder response = new StringBuilder();
            String line;

            while ((line = in.readLine()) != null) {
                response.append(line);
            }

            in.close();

            System.out.print(response.toString());

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
```

{% endtab %}
{% endtabs %}

**Response**

```json
{
	"parser": "231fc251-decf-45ee-b7d8-738ac4a8hj76",
	"version": 0,
	"result": {
		"quotes": [
			{
				"text": "“A reader lives a thousand lives before he dies, said Jojen. The man who never reads lives only one.”",
				"author": "George R.R. Martin"
			},
			{
				"text": "“You can never get a cup of tea large enough or a book long enough to suit me.”",
				"author": "C.S. Lewis",
			},
			{
				"text": "“You believe lies so you eventually learn to trust no one but yourself.”",
				"author": "Marilyn Monroe",
			},
			{
				"title": "“If you can make a woman laugh, you can make her do anything.”",
				"author": "Marilyn Monroe",
			},
			{
				"text": "“Life is like riding a bicycle. To keep your balance, you must keep moving.”",
				"author": "Albert Einstein",
			},
			{
				"text": "“The real lover is the man who can thrill you by kissing your forehead or smiling into your eyes or just staring into space.”",
				"author": "Marilyn Monroe",
			},
			{
				"text": "“A wise girl kisses but doesn't love, listens but doesn't believe, and leaves before she is left.”",
				"author": "Marilyn Monroe",
			},
			{
				"text": "“Only in the darkness can you see the stars.”",
				"author": "Martin Luther King Jr.",
			},
			{
				"text": "“It matters not what someone is born, but what they grow to be.”",
				"author": "J.K. Rowling",
			},
			{
				"text": "“Love does not begin and end the way we seem to think it does. Love is a battle, love is a war; love is a growing up.”",
				"author": "James Baldwin",
			}
		],
		"pagination": [
			{
				"previous": "/page/4/",
				"next": "/page/6/"
			}
		],
	}
}
```

The exact shape of `result` depends on the fields the parser learned.

{% hint style="warning" %}
**Caveats**

* **Empry** `result` - check the parser status. If it is still `generating`, prasing won't work yet.
* **Missing fields** - The page may have slightly different layout than the example URLs. Use `PATCH` to add field definitions with explicit descriptions and/or CSS/XPATH selectors instead.
  {% endhint %}


---

# 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:

```
GET https://docs.scraperapi.com/ai-parser/endpoints/parse-a-url.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
