# Parse pages

> Read metadata, links, images, headings, e-mail addresses, phone numbers, tables and JSON-LD out of any HTML answer with one option, without writing selectors.

Source: https://docs.virginproxy.com/parse/

Some things every page has: a title, links, images, headings, maybe tables and structured data. `parse` reads them for you and returns them as clean JSON in `parsed` – no selectors needed.

**cURL**

```bash
curl https://api.virginproxy.com/v1/requests \
  -H "Authorization: Bearer $VP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://shop.example/product/42",
    "parse": [
      "metadata",
      "links",
      "tables",
      "json_ld"
    ]
  }'
```

**Python**

```python
import os, requests

r = requests.post(
    "https://api.virginproxy.com/v1/requests",
    headers={"Authorization": "Bearer " + os.environ["VP_KEY"]},
    json={
        "url": "https://shop.example/product/42",
        "parse": ["metadata", "links", "tables", "json_ld"],
    },
    timeout=180,
)
data = r.json()
if not r.ok:
    raise SystemExit(data["error"]["code"] + ": " + data["error"]["message"])
print(data["parsed"]["metadata"])
print(data["parsed"]["json_ld"])
```

**Node.js**

```javascript
const res = await fetch("https://api.virginproxy.com/v1/requests", {
  method: "POST",
  headers: { Authorization: "Bearer " + process.env.VP_KEY, "Content-Type": "application/json" },
  body: JSON.stringify({
    url: "https://shop.example/product/42",
    parse: ["metadata", "links", "tables", "json_ld"],
  }),
  signal: AbortSignal.timeout(180_000),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.code + ": " + data.error.message);
console.log(data.parsed.metadata);
console.log(data.parsed.json_ld);
```

**Python SDK**

```pysdk
from virginproxy import VirginProxy  # docs.virginproxy.com/sdk/virginproxy.py

vp = VirginProxy()  # reads VP_KEY
data = vp.request({
    "url": "https://shop.example/product/42",
    "parse": ["metadata", "links", "tables", "json_ld"],
})
print(data)
```

**Node SDK**

```nodesdk
import { VirginProxy } from "./virginproxy.mjs"; // docs.virginproxy.com/sdk/virginproxy.mjs

const vp = new VirginProxy(); // reads VP_KEY
const data = await vp.request({
  url: "https://shop.example/product/42",
  parse: ["metadata", "links", "tables", "json_ld"],
});
console.log(data);
```

**PHP**

```php
<?php
$ch = curl_init("https://api.virginproxy.com/v1/requests");
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 180,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer " . getenv("VP_KEY"),
        "Content-Type: application/json",
    ],
    CURLOPT_POSTFIELDS => json_encode([
        "url" => "https://shop.example/product/42",
        "parse" => ["metadata", "links", "tables", "json_ld"],
    ], JSON_UNESCAPED_SLASHES),
]);
$data = json_decode(curl_exec($ch), true);
if (isset($data["error"])) {
    exit($data["error"]["code"] . ": " . $data["error"]["message"] . PHP_EOL);
}
echo json_encode($data["parsed"]["metadata"], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), PHP_EOL;
echo json_encode($data["parsed"]["json_ld"], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), PHP_EOL;
```

**Go**

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"log"
	"net/http"
	"os"
	"time"
)

func main() {
	payload := []byte(`{
  "url": "https://shop.example/product/42",
  "parse": [
    "metadata",
    "links",
    "tables",
    "json_ld"
  ]
}`)
	req, err := http.NewRequest("POST", "https://api.virginproxy.com/v1/requests", bytes.NewReader(payload))
	if err != nil {
		log.Fatal(err)
	}
	req.Header.Set("Authorization", "Bearer "+os.Getenv("VP_KEY"))
	req.Header.Set("Content-Type", "application/json")

	client := &http.Client{Timeout: 180 * time.Second}
	res, err := client.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer res.Body.Close()

	var data map[string]any
	if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
		log.Fatal(err)
	}
	if res.StatusCode >= 300 {
		e := data["error"].(map[string]any)
		log.Fatalf("%v: %v", e["code"], e["message"])
	}
	fmt.Println(data["parsed"].(map[string]any)["metadata"])
	fmt.Println(data["parsed"].(map[string]any)["json_ld"])
}
```

POST`/v1/requests`[≈ 1 credit](https://docs.virginproxy.com/billing/#cost)[Open in Playground](https://dash.virginproxy.com/playground#request=eyJ1cmwiOiJodHRwczovL3Nob3AuZXhhbXBsZS9wcm9kdWN0LzQyIiwicGFyc2UiOlsibWV0YWRhdGEiLCJsaW5rcyIsInRhYmxlcyIsImpzb25fbGQiXX0)

`"parse": true` returns everything. A list returns exactly the keys you asked for:

*Response · 200 OK (shortened):*

```json
{
  "status": 200,
  "final_url": "https://shop.example/product/42",
  "parsed": {
    "metadata": {
      "title": "Trail Runner 2 – Shop Example",
      "description": "Light trail running shoe with a grippy sole.",
      "canonical": "https://shop.example/product/42",
      "lang": "en",
      "robots": "index, follow",
      "favicon": "https://shop.example/favicon.ico",
      "og": { "title": "Trail Runner 2", "type": "product", "image": "https://shop.example/img/42.jpg" },
      "twitter": { "card": "summary_large_image" },
      "hreflang": [{ "lang": "de", "url": "https://shop.example/de/product/42" }]
    },
    "links": [
      { "url": "https://shop.example/category/running", "text": "Running", "rel": null, "internal": true },
      { "url": "https://social.example/shopexample", "text": "Social profile", "rel": "noopener", "internal": false }
    ],
    "images": [
      { "url": "https://shop.example/img/42.jpg", "alt": "Trail Runner 2, side view", "width": 800, "height": 600 }
    ],
    "headings": [
      { "level": 1, "text": "Trail Runner 2" },
      { "level": 2, "text": "Details" }
    ],
    "emails": ["support@shop.example"],
    "phones": ["+493012345678"],
    "tables": [
      { "caption": "Sizes", "headers": ["EU", "UK", "US"], "rows": [["42", "8", "9"], ["43", "9", "10"]] }
    ],
    "json_ld": [
      { "@context": "https://schema.org", "@type": "Product", "name": "Trail Runner 2", "offers": { "@type": "Offer", "price": "129.00", "priceCurrency": "EUR" } }
    ]
  },
  "cost": { "credits": 1 }
}
```

## What can be parsed

| Key | Result | Limit |
| --- | --- | --- |
| `metadata` | `{title, description, canonical, lang, robots, favicon, og, twitter, hreflang}`. `og` and `twitter` are objects of the Open Graph and Twitter tags without their prefix; `hreflang` is a list of `{lang, url}`. Missing values are `null` or empty. | – |
| `links` | `[{url, text, rel, internal}]`, absolute, without `javascript:`, `mailto:` and `tel:` links, one entry per URL. `internal` is `true` when the link points to the host of `final_url`. | 2,000 |
| `images` | `[{url, alt, width, height}]` from `src`, otherwise `data-src` or the first `srcset` entry. Width and height are numbers or `null`. | 1,000 |
| `headings` | `[{level, text}]` for `h1` to `h6`, in page order. | 500 |
| `emails` | Addresses from `mailto:` links and from the text, each once. | 500 |
| `phones` | Numbers from `tel:` links, reduced to `+` and digits. Numbers in running text are not guessed. | 500 |
| `tables` | `[{caption, headers, rows}]`. Headers come from `thead th`, otherwise from the first row of `th` cells; cells are trimmed. | 50 tables, 1,000 rows each |
| `json_ld` | Every `<script type="application/ld+json">`, parsed. A `@graph` is split into its objects; invalid JSON is skipped. | 100 |

## How it behaves

- Parsing always reads the original HTML, also when you ask for a different [format](https://docs.virginproxy.com/formats/). With `render` it reads the finished page.
- An answer that is not HTML returns empty values: `"metadata": null` and empty lists.
- Parsing costs nothing extra.
- An unknown key is answered with `invalid_parse` (400).

> **Tip:** Need a value that is not in this list, like a price in a specific element? Use [extract](https://docs.virginproxy.com/extract/), and combine both in one request.
