## Table of Contents

- [data](#data)
  - [CLI Microlink API example](#cli-microlink-api-example)
  - [cURL Microlink API example](#curl-microlink-api-example)
  - [JavaScript Microlink API example](#javascript-microlink-api-example)
  - [Python Microlink API example](#python-microlink-api-example)
  - [Ruby Microlink API example](#ruby-microlink-api-example)
  - [PHP Microlink API example](#php-microlink-api-example)
  - [Golang Microlink API example](#golang-microlink-api-example)
- [Response structure](#response-structure)
- [Rule properties](#rule-properties)
- [Extracting multiple fields](#extracting-multiple-fields)
  - [CLI Microlink API example](#cli-microlink-api-example-1)
  - [cURL Microlink API example](#curl-microlink-api-example-1)
  - [JavaScript Microlink API example](#javascript-microlink-api-example-1)
  - [Python Microlink API example](#python-microlink-api-example-1)
  - [Ruby Microlink API example](#ruby-microlink-api-example-1)
  - [PHP Microlink API example](#php-microlink-api-example-1)
  - [Golang Microlink API example](#golang-microlink-api-example-1)
- [Extracting collections](#extracting-collections)
  - [CLI Microlink API example](#cli-microlink-api-example-2)
  - [cURL Microlink API example](#curl-microlink-api-example-2)
  - [JavaScript Microlink API example](#javascript-microlink-api-example-2)
  - [Python Microlink API example](#python-microlink-api-example-2)
  - [Ruby Microlink API example](#ruby-microlink-api-example-2)
  - [PHP Microlink API example](#php-microlink-api-example-2)
  - [Golang Microlink API example](#golang-microlink-api-example-2)
- [Nested data extraction](#nested-data-extraction)
  - [CLI Microlink API example](#cli-microlink-api-example-3)
  - [cURL Microlink API example](#curl-microlink-api-example-3)
  - [JavaScript Microlink API example](#javascript-microlink-api-example-3)
  - [Python Microlink API example](#python-microlink-api-example-3)
  - [Ruby Microlink API example](#ruby-microlink-api-example-3)
  - [PHP Microlink API example](#php-microlink-api-example-3)
  - [Golang Microlink API example](#golang-microlink-api-example-3)
- [Fallback values](#fallback-values)
  - [CLI Microlink API example](#cli-microlink-api-example-4)
  - [cURL Microlink API example](#curl-microlink-api-example-4)
  - [JavaScript Microlink API example](#javascript-microlink-api-example-4)
  - [Python Microlink API example](#python-microlink-api-example-4)
  - [Ruby Microlink API example](#ruby-microlink-api-example-4)
  - [PHP Microlink API example](#php-microlink-api-example-4)
  - [Golang Microlink API example](#golang-microlink-api-example-4)

---

[API](https://microlink.io/docs/api/getting-started/overview)

[GUIDES](https://microlink.io/docs/guides) [MQL](https://microlink.io/docs/mql/getting-started/overview) [SDK](https://microlink.io/docs/sdk/getting-started/overview) [CARDS](https://microlink.io/docs/cards/getting-started/overview) [Skills](https://microlink.io/skills)

API GUIDES MQL SDK CARDS Skills

Getting Started

[Overview](https://microlink.io/docs/api/getting-started/overview)

[Data fields](https://microlink.io/docs/api/getting-started/data-fields)

[CLI](https://microlink.io/docs/api/getting-started/cli)

[MCP](https://microlink.io/docs/api/getting-started/mcp)

Basics

[Authentication](https://microlink.io/docs/api/basics/authentication)

[Cache](https://microlink.io/docs/api/basics/cache)

[Compression](https://microlink.io/docs/api/basics/compression)

[Endpoint](https://microlink.io/docs/api/basics/endpoint)

[Error codes](https://microlink.io/docs/api/basics/error-codes)

[Format](https://microlink.io/docs/api/basics/format)

[Rate limit](https://microlink.io/docs/api/basics/rate-limit)

Query Parameters

[adblock](https://microlink.io/docs/api/parameters/adblock)

[animations](https://microlink.io/docs/api/parameters/animations)

[audio](https://microlink.io/docs/api/parameters/audio)

[cacheKey](https://microlink.io/docs/api/parameters/cacheKey)

[click](https://microlink.io/docs/api/parameters/click)

[colorScheme](https://microlink.io/docs/api/parameters/colorScheme)

[data](https://microlink.io/docs/api/parameters/data)

[device](https://microlink.io/docs/api/parameters/device)

[embed](https://microlink.io/docs/api/parameters/embed)

[filename](https://microlink.io/docs/api/parameters/filename)

[filter](https://microlink.io/docs/api/parameters/filter)

[force](https://microlink.io/docs/api/parameters/force)

[function](https://microlink.io/docs/api/parameters/function)

[headers](https://microlink.io/docs/api/parameters/headers)

[iframe](https://microlink.io/docs/api/parameters/iframe)

[insights](https://microlink.io/docs/api/parameters/insights)

[lighthouse](https://microlink.io/docs/api/parameters/insights/lighthouse)

[technologies](https://microlink.io/docs/api/parameters/insights/technologies)

[javascript](https://microlink.io/docs/api/parameters/javascript)

[mediaType](https://microlink.io/docs/api/parameters/mediaType)

[meta](https://microlink.io/docs/api/parameters/meta)

[modules](https://microlink.io/docs/api/parameters/modules)

[palette](https://microlink.io/docs/api/parameters/palette)

[pdf](https://microlink.io/docs/api/parameters/pdf)

[format](https://microlink.io/docs/api/parameters/pdf/format)

[height](https://microlink.io/docs/api/parameters/pdf/height)

[landscape](https://microlink.io/docs/api/parameters/pdf/landscape)

[margin](https://microlink.io/docs/api/parameters/pdf/margin)

[pageRanges](https://microlink.io/docs/api/parameters/pdf/pageRanges)

[scale](https://microlink.io/docs/api/parameters/pdf/scale)

[width](https://microlink.io/docs/api/parameters/pdf/width)

[ping](https://microlink.io/docs/api/parameters/ping)

[prerender](https://microlink.io/docs/api/parameters/prerender)

[proxy](https://microlink.io/docs/api/parameters/proxy)

[retry](https://microlink.io/docs/api/parameters/retry)

[screenshot](https://microlink.io/docs/api/parameters/screenshot)

[animated](https://microlink.io/docs/api/parameters/screenshot/animated)

[codeScheme](https://microlink.io/docs/api/parameters/screenshot/codeScheme)

[element](https://microlink.io/docs/api/parameters/screenshot/element)

[fullPage](https://microlink.io/docs/api/parameters/screenshot/fullPage)

[overlay](https://microlink.io/docs/api/parameters/screenshot/overlay)

[omitBackground](https://microlink.io/docs/api/parameters/screenshot/omitBackground)

[type](https://microlink.io/docs/api/parameters/screenshot/type)

[scripts](https://microlink.io/docs/api/parameters/scripts)

[scroll](https://microlink.io/docs/api/parameters/scroll)

[styles](https://microlink.io/docs/api/parameters/styles)

[staleTtl](https://microlink.io/docs/api/parameters/staleTtl)

[timeout](https://microlink.io/docs/api/parameters/timeout)

[ttl](https://microlink.io/docs/api/parameters/ttl)

[url](https://microlink.io/docs/api/parameters/url)

[video](https://microlink.io/docs/api/parameters/video)

[viewport](https://microlink.io/docs/api/parameters/viewport)

[waitForSelector](https://microlink.io/docs/api/parameters/waitForSelector)

[waitForTimeout](https://microlink.io/docs/api/parameters/waitForTimeout)

[waitUntil](https://microlink.io/docs/api/parameters/waitUntil)

API GUIDES MQL SDK CARDS Skills

Getting Started

[Overview](https://microlink.io/docs/api/getting-started/overview)

[Data fields](https://microlink.io/docs/api/getting-started/data-fields)

[CLI](https://microlink.io/docs/api/getting-started/cli)

[MCP](https://microlink.io/docs/api/getting-started/mcp)

Basics

[Authentication](https://microlink.io/docs/api/basics/authentication)

[Cache](https://microlink.io/docs/api/basics/cache)

[Compression](https://microlink.io/docs/api/basics/compression)

[Endpoint](https://microlink.io/docs/api/basics/endpoint)

[Error codes](https://microlink.io/docs/api/basics/error-codes)

[Format](https://microlink.io/docs/api/basics/format)

[Rate limit](https://microlink.io/docs/api/basics/rate-limit)

Query Parameters

[adblock](https://microlink.io/docs/api/parameters/adblock)

[animations](https://microlink.io/docs/api/parameters/animations)

[audio](https://microlink.io/docs/api/parameters/audio)

[cacheKey](https://microlink.io/docs/api/parameters/cacheKey)

[click](https://microlink.io/docs/api/parameters/click)

[colorScheme](https://microlink.io/docs/api/parameters/colorScheme)

[data](https://microlink.io/docs/api/parameters/data)

[device](https://microlink.io/docs/api/parameters/device)

[embed](https://microlink.io/docs/api/parameters/embed)

[filename](https://microlink.io/docs/api/parameters/filename)

[filter](https://microlink.io/docs/api/parameters/filter)

[force](https://microlink.io/docs/api/parameters/force)

[function](https://microlink.io/docs/api/parameters/function)

[headers](https://microlink.io/docs/api/parameters/headers)

[iframe](https://microlink.io/docs/api/parameters/iframe)

[insights](https://microlink.io/docs/api/parameters/insights)

[lighthouse](https://microlink.io/docs/api/parameters/insights/lighthouse)

[technologies](https://microlink.io/docs/api/parameters/insights/technologies)

[javascript](https://microlink.io/docs/api/parameters/javascript)

[mediaType](https://microlink.io/docs/api/parameters/mediaType)

[meta](https://microlink.io/docs/api/parameters/meta)

[modules](https://microlink.io/docs/api/parameters/modules)

[palette](https://microlink.io/docs/api/parameters/palette)

[pdf](https://microlink.io/docs/api/parameters/pdf)

[format](https://microlink.io/docs/api/parameters/pdf/format)

[height](https://microlink.io/docs/api/parameters/pdf/height)

[landscape](https://microlink.io/docs/api/parameters/pdf/landscape)

[margin](https://microlink.io/docs/api/parameters/pdf/margin)

[pageRanges](https://microlink.io/docs/api/parameters/pdf/pageRanges)

[scale](https://microlink.io/docs/api/parameters/pdf/scale)

[width](https://microlink.io/docs/api/parameters/pdf/width)

[ping](https://microlink.io/docs/api/parameters/ping)

[prerender](https://microlink.io/docs/api/parameters/prerender)

[proxy](https://microlink.io/docs/api/parameters/proxy)

[retry](https://microlink.io/docs/api/parameters/retry)

[screenshot](https://microlink.io/docs/api/parameters/screenshot)

[animated](https://microlink.io/docs/api/parameters/screenshot/animated)

[codeScheme](https://microlink.io/docs/api/parameters/screenshot/codeScheme)

[element](https://microlink.io/docs/api/parameters/screenshot/element)

[fullPage](https://microlink.io/docs/api/parameters/screenshot/fullPage)

[overlay](https://microlink.io/docs/api/parameters/screenshot/overlay)

[omitBackground](https://microlink.io/docs/api/parameters/screenshot/omitBackground)

[type](https://microlink.io/docs/api/parameters/screenshot/type)

[scripts](https://microlink.io/docs/api/parameters/scripts)

[scroll](https://microlink.io/docs/api/parameters/scroll)

[styles](https://microlink.io/docs/api/parameters/styles)

[staleTtl](https://microlink.io/docs/api/parameters/staleTtl)

[timeout](https://microlink.io/docs/api/parameters/timeout)

[ttl](https://microlink.io/docs/api/parameters/ttl)

[url](https://microlink.io/docs/api/parameters/url)

[video](https://microlink.io/docs/api/parameters/video)

[viewport](https://microlink.io/docs/api/parameters/viewport)

[waitForSelector](https://microlink.io/docs/api/parameters/waitForSelector)

[waitForTimeout](https://microlink.io/docs/api/parameters/waitForTimeout)

[waitUntil](https://microlink.io/docs/api/parameters/waitUntil)

## data

[Copy for LLM](https://microlink.io/docs/api/parameters/data.md "Copy content for LLM")

\|

[View as Markdown](https://microlink.io/docs/api/parameters/data.md "View content as Markdown")

Type: \<object\>

It enables specific data extraction over the target [url](https://microlink.io/docs/api/parameters/url), turning Microlink API into a powerful web scraping tool.

The following examples show how to use the Microlink API with CLI, cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://kikobeats.com' URL with 'data' API parameter:

### CLI Microlink API example

```bash
microlink https://kikobeats.com&data.avatar.selector=#avatar&data.avatar.type=image&data.avatar.attr=src
```

### cURL Microlink API example

```bash
curl -G "https://api.microlink.io" \
  -d "url=https://kikobeats.com" \
  -d "data.avatar.selector=#avatar" \
  -d "data.avatar.type=image" \
  -d "data.avatar.attr=src"
```

### JavaScript Microlink API example

```javascript
import mql from '@microlink/mql'

const { data } = await mql('https://kikobeats.com', {
  data: {
    avatar: {
      selector: "#avatar",
      type: "image",
      attr: "src"
    }
  }
})
```

### Python Microlink API example

```python
import requests

url = "https://api.microlink.io/"

querystring = {
    "url": "https://kikobeats.com",
    "data.avatar.selector": "#avatar",
    "data.avatar.type": "image",
    "data.avatar.attr": "src"
}

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

print(response.json())
```

### Ruby Microlink API example

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

base_url = "https://api.microlink.io/"

params = {
  url: "https://kikobeats.com",
  data.avatar.selector: "#avatar",
  data.avatar.type: "image",
  data.avatar.attr: "src"
}

uri = URI(base_url)
uri.query = URI.encode_www_form(params)

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Get.new(uri)
response = http.request(request)

puts response.body
```

### PHP Microlink API example

```php
<?php

$baseUrl = "https://api.microlink.io/";

$params = [
    "url" => "https://kikobeats.com",
    "data.avatar.selector" => "#avatar",
    "data.avatar.type" => "image",
    "data.avatar.attr" => "src"
];

$query = http_build_query($params);
$url = $baseUrl . '?' . $query;

$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET"
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #: " . $err;
} else {
    echo $response;
}
```

### Golang Microlink API example

```
package main

import (
    "fmt"
    "net/http"
    "net/url"
    "io"
)

func main() {
    baseURL := "https://api.microlink.io"

    u, err := url.Parse(baseURL)
    if err != nil {
        panic(err)
    }
    q := u.Query()
    q.Set("url", "https://kikobeats.com")
    q.Set("data.avatar.selector", "#avatar")
    q.Set("data.avatar.type", "image")
    q.Set("data.avatar.attr", "src")
    u.RawQuery = q.Encode()

    req, err := http.NewRequest("GET", u.String(), nil)
    if err != nil {
        panic(err)
    }

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, err := io.ReadAll(resp.Body)
    if err != nil {
        panic(err)
    }

    fmt.Println(string(body))
}
```

```javascript
importmqlfrom'@microlink/mql'

const{data}=awaitmql('https://kikobeats.com',{

data:{

avatar:{

selector:"#avatar",

type:"image",

attr:"src"

}

}

})
```

The data extraction needs to be defined at least with a CSS selector.

## Response structure

The extracted data will be part of the `data` payload in the response:

```json
{

"data":{

"avatar":{

"url":"https://d33wubrfki0l68.cloudfront.net/ad0e96f5e30e3c65b7ff31e5a637fea070356f0b/eaa58/images/avatar.jpg",

"width":500,

"height":500,

"type":"jpg",

"size":53310,

"size_pretty":"53.3 kB"

}

},

"status":"success"

}
```

## Rule properties

Each data rule accepts the following properties:

| Property                                                      | Type       | Description                                                                 |
| ------------------------------------------------------------- | ---------- | --------------------------------------------------------------------------- |
| [selector](https://microlink.io/docs/mql/data/selector)       | `string`   | CSS selector to target the element                                          |
| [selectorAll](https://microlink.io/docs/mql/data/selectorAll) | `string`   | CSS selector to target multiple elements                                    |
| [attr](https://microlink.io/docs/mql/data/attr)               | `string`   | HTML attribute to extract (e.g., `href`, `src`)                             |
| [type](https://microlink.io/docs/mql/data/type)               | `string`   | Data type for validation (`string`, `number`, `date`, `image`, `url`, etc.) |
| [evaluate](https://microlink.io/docs/mql/data/evaluate)       | `function` | JavaScript function to transform the extracted value                        |

## Extracting multiple fields

You can extract multiple data fields in a single request:

The following examples show how to use the Microlink API with CLI, cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://news.ycombinator.com' URL with 'data' API parameter:

### CLI Microlink API example

```bash
microlink https://news.ycombinator.com&data.headline.selector='.titleline > a'&data.headline.attr=text&data.link.selector='.titleline > a'&data.link.attr=href&data.link.type=url&data.score.selector=.score&data.score.attr=text
```

### cURL Microlink API example

```bash
curl -G "https://api.microlink.io" \
  -d "url=https://news.ycombinator.com" \
  -d "data.headline.selector=.titleline%20%3E%20a" \
  -d "data.headline.attr=text" \
  -d "data.link.selector=.titleline%20%3E%20a" \
  -d "data.link.attr=href" \
  -d "data.link.type=url" \
  -d "data.score.selector=.score" \
  -d "data.score.attr=text"
```

### JavaScript Microlink API example

```javascript
import mql from '@microlink/mql'

const { data } = await mql('https://news.ycombinator.com', {
  data: {
    headline: {
      selector: ".titleline > a",
      attr: "text"
    },
    link: {
      selector: ".titleline > a",
      attr: "href",
      type: "url"
    },
    score: {
      selector: ".score",
      attr: "text"
    }
  }
})
```

### Python Microlink API example

```python
import requests

url = "https://api.microlink.io/"

querystring = {
    "url": "https://news.ycombinator.com",
    "data.headline.selector": ".titleline > a",
    "data.headline.attr": "text",
    "data.link.selector": ".titleline > a",
    "data.link.attr": "href",
    "data.link.type": "url",
    "data.score.selector": ".score",
    "data.score.attr": "text"
}

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

print(response.json())
```

### Ruby Microlink API example

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

base_url = "https://api.microlink.io/"

params = {
  url: "https://news.ycombinator.com",
  data.headline.selector: ".titleline > a",
  data.headline.attr: "text",
  data.link.selector: ".titleline > a",
  data.link.attr: "href",
  data.link.type: "url",
  data.score.selector: ".score",
  data.score.attr: "text"
}

uri = URI(base_url)
uri.query = URI.encode_www_form(params)

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Get.new(uri)
response = http.request(request)

puts response.body
```

### PHP Microlink API example

```php
<?php

$baseUrl = "https://api.microlink.io/";

$params = [
    "url" => "https://news.ycombinator.com",
    "data.headline.selector" => ".titleline > a",
    "data.headline.attr" => "text",
    "data.link.selector" => ".titleline > a",
    "data.link.attr" => "href",
    "data.link.type" => "url",
    "data.score.selector" => ".score",
    "data.score.attr" => "text"
];

$query = http_build_query($params);
$url = $baseUrl . '?' . $query;

$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET"
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #: " . $err;
} else {
    echo $response;
}
```

### Golang Microlink API example

```
package main

import (
    "fmt"
    "net/http"
    "net/url"
    "io"
)

func main() {
    baseURL := "https://api.microlink.io"

    u, err := url.Parse(baseURL)
    if err != nil {
        panic(err)
    }
    q := u.Query()
    q.Set("url", "https://news.ycombinator.com")
    q.Set("data.headline.selector", ".titleline > a")
    q.Set("data.headline.attr", "text")
    q.Set("data.link.selector", ".titleline > a")
    q.Set("data.link.attr", "href")
    q.Set("data.link.type", "url")
    q.Set("data.score.selector", ".score")
    q.Set("data.score.attr", "text")
    u.RawQuery = q.Encode()

    req, err := http.NewRequest("GET", u.String(), nil)
    if err != nil {
        panic(err)
    }

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, err := io.ReadAll(resp.Body)
    if err != nil {
        panic(err)
    }

    fmt.Println(string(body))
}
```

```javascript
importmqlfrom'@microlink/mql'

const{data}=awaitmql('https://news.ycombinator.com',{

data:{

headline:{

selector:".titleline > a",

attr:"text"

},

link:{

selector:".titleline > a",

attr:"href",

type:"url"

},

score:{

selector:".score",

attr:"text"

}

}

})
```

Extract title, link, and score from Hacker News.

## Extracting collections

Use [selectorAll](https://microlink.io/docs/mql/data/selectorAll) to extract multiple matching elements as an array:

The following examples show how to use the Microlink API with CLI, cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://news.ycombinator.com' URL with 'data' API parameter:

### CLI Microlink API example

```bash
microlink https://news.ycombinator.com&data.stories.selectorAll='.titleline > a'&data.stories.attr=text
```

### cURL Microlink API example

```bash
curl -G "https://api.microlink.io" \
  -d "url=https://news.ycombinator.com" \
  -d "data.stories.selectorAll=.titleline%20%3E%20a" \
  -d "data.stories.attr=text"
```

### JavaScript Microlink API example

```javascript
import mql from '@microlink/mql'

const { data } = await mql('https://news.ycombinator.com', {
  data: {
    stories: {
      selectorAll: ".titleline > a",
      attr: "text"
    }
  }
})
```

### Python Microlink API example

```python
import requests

url = "https://api.microlink.io/"

querystring = {
    "url": "https://news.ycombinator.com",
    "data.stories.selectorAll": ".titleline > a",
    "data.stories.attr": "text"
}

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

print(response.json())
```

### Ruby Microlink API example

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

base_url = "https://api.microlink.io/"

params = {
  url: "https://news.ycombinator.com",
  data.stories.selectorAll: ".titleline > a",
  data.stories.attr: "text"
}

uri = URI(base_url)
uri.query = URI.encode_www_form(params)

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Get.new(uri)
response = http.request(request)

puts response.body
```

### PHP Microlink API example

```php
<?php

$baseUrl = "https://api.microlink.io/";

$params = [
    "url" => "https://news.ycombinator.com",
    "data.stories.selectorAll" => ".titleline > a",
    "data.stories.attr" => "text"
];

$query = http_build_query($params);
$url = $baseUrl . '?' . $query;

$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET"
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #: " . $err;
} else {
    echo $response;
}
```

### Golang Microlink API example

```
package main

import (
    "fmt"
    "net/http"
    "net/url"
    "io"
)

func main() {
    baseURL := "https://api.microlink.io"

    u, err := url.Parse(baseURL)
    if err != nil {
        panic(err)
    }
    q := u.Query()
    q.Set("url", "https://news.ycombinator.com")
    q.Set("data.stories.selectorAll", ".titleline > a")
    q.Set("data.stories.attr", "text")
    u.RawQuery = q.Encode()

    req, err := http.NewRequest("GET", u.String(), nil)
    if err != nil {
        panic(err)
    }

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, err := io.ReadAll(resp.Body)
    if err != nil {
        panic(err)
    }

    fmt.Println(string(body))
}
```

```javascript
importmqlfrom'@microlink/mql'

const{data}=awaitmql('https://news.ycombinator.com',{

data:{

stories:{

selectorAll:".titleline > a",

attr:"text"

}

}

})
```

Extract all story titles as an array.

## Nested data extraction

For complex DOM structures, use [nested rules](https://microlink.io/docs/mql/rules/nested) to organize your data hierarchically:

The following examples show how to use the Microlink API with CLI, cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://news.ycombinator.com' URL with 'data' API parameter:

### CLI Microlink API example

```bash
microlink https://news.ycombinator.com&data.stories.selectorAll=.athing&data.stories.attr.title.selector='.titleline > a'&data.stories.attr.title.attr=text&data.stories.attr.href.selector='.titleline > a'&data.stories.attr.href.attr=href
```

### cURL Microlink API example

```bash
curl -G "https://api.microlink.io" \
  -d "url=https://news.ycombinator.com" \
  -d "data.stories.selectorAll=.athing" \
  -d "data.stories.attr.title.selector=.titleline%20%3E%20a" \
  -d "data.stories.attr.title.attr=text" \
  -d "data.stories.attr.href.selector=.titleline%20%3E%20a" \
  -d "data.stories.attr.href.attr=href"
```

### JavaScript Microlink API example

```javascript
import mql from '@microlink/mql'

const { data } = await mql('https://news.ycombinator.com', {
  data: {
    stories: {
      selectorAll: ".athing",
      attr: {
        title: {
          selector: ".titleline > a",
          attr: "text"
        },
        href: {
          selector: ".titleline > a",
          attr: "href"
        }
      }
    }
  }
})
```

### Python Microlink API example

```python
import requests

url = "https://api.microlink.io/"

querystring = {
    "url": "https://news.ycombinator.com",
    "data.stories.selectorAll": ".athing",
    "data.stories.attr.title.selector": ".titleline > a",
    "data.stories.attr.title.attr": "text",
    "data.stories.attr.href.selector": ".titleline > a",
    "data.stories.attr.href.attr": "href"
}

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

print(response.json())
```

### Ruby Microlink API example

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

base_url = "https://api.microlink.io/"

params = {
  url: "https://news.ycombinator.com",
  data.stories.selectorAll: ".athing",
  data.stories.attr.title.selector: ".titleline > a",
  data.stories.attr.title.attr: "text",
  data.stories.attr.href.selector: ".titleline > a",
  data.stories.attr.href.attr: "href"
}

uri = URI(base_url)
uri.query = URI.encode_www_form(params)

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Get.new(uri)
response = http.request(request)

puts response.body
```

### PHP Microlink API example

```php
<?php

$baseUrl = "https://api.microlink.io/";

$params = [
    "url" => "https://news.ycombinator.com",
    "data.stories.selectorAll" => ".athing",
    "data.stories.attr.title.selector" => ".titleline > a",
    "data.stories.attr.title.attr" => "text",
    "data.stories.attr.href.selector" => ".titleline > a",
    "data.stories.attr.href.attr" => "href"
];

$query = http_build_query($params);
$url = $baseUrl . '?' . $query;

$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET"
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #: " . $err;
} else {
    echo $response;
}
```

### Golang Microlink API example

```
package main

import (
    "fmt"
    "net/http"
    "net/url"
    "io"
)

func main() {
    baseURL := "https://api.microlink.io"

    u, err := url.Parse(baseURL)
    if err != nil {
        panic(err)
    }
    q := u.Query()
    q.Set("url", "https://news.ycombinator.com")
    q.Set("data.stories.selectorAll", ".athing")
    q.Set("data.stories.attr.title.selector", ".titleline > a")
    q.Set("data.stories.attr.title.attr", "text")
    q.Set("data.stories.attr.href.selector", ".titleline > a")
    q.Set("data.stories.attr.href.attr", "href")
    u.RawQuery = q.Encode()

    req, err := http.NewRequest("GET", u.String(), nil)
    if err != nil {
        panic(err)
    }

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, err := io.ReadAll(resp.Body)
    if err != nil {
        panic(err)
    }

    fmt.Println(string(body))
}
```

```javascript
importmqlfrom'@microlink/mql'

const{data}=awaitmql('https://news.ycombinator.com',{

data:{

stories:{

selectorAll:".athing",

attr:{

title:{

selector:".titleline > a",

attr:"text"

},

href:{

selector:".titleline > a",

attr:"href"

}

}

}

}

})
```

Nested rules let each matched item return a structured object instead of a single value.

## Fallback values

Define [fallback rules](https://microlink.io/docs/mql/rules/fallbacks) to ensure data extraction succeeds even when the primary selector fails:

The following examples show how to use the Microlink API with CLI, cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://example.com' URL with 'data' API parameter:

### CLI Microlink API example

```bash
microlink https://example.com&data.title='[object Object],[object Object],[object Object]'
```

### cURL Microlink API example

```bash
curl -G "https://api.microlink.io" \
  -d "url=https://example.com" \
  -d "data.title=%5Bobject%20Object%5D%2C%5Bobject%20Object%5D%2C%5Bobject%20Object%5D"
```

### JavaScript Microlink API example

```javascript
import mql from '@microlink/mql'

const { data } = await mql('https://example.com', {
  data: {
    title: [
      {
        selector: 'meta[property="og:title"]',
        attr: "content"
      },
      {
        selector: "title",
        attr: "text"
      },
      {
        selector: "h1",
        attr: "text"
      }
    ]
  }
})
```

### Python Microlink API example

```python
import requests

url = "https://api.microlink.io/"

querystring = {
    "url": "https://example.com",
    "data.title": "[object Object],[object Object],[object Object]"
}

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

print(response.json())
```

### Ruby Microlink API example

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

base_url = "https://api.microlink.io/"

params = {
  url: "https://example.com",
  data.title: "[object Object],[object Object],[object Object]"
}

uri = URI(base_url)
uri.query = URI.encode_www_form(params)

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Get.new(uri)
response = http.request(request)

puts response.body
```

### PHP Microlink API example

```php
<?php

$baseUrl = "https://api.microlink.io/";

$params = [
    "url" => "https://example.com",
    "data.title" => "[object Object],[object Object],[object Object]"
];

$query = http_build_query($params);
$url = $baseUrl . '?' . $query;

$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET"
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #: " . $err;
} else {
    echo $response;
}
```

### Golang Microlink API example

```
package main

import (
    "fmt"
    "net/http"
    "net/url"
    "io"
)

func main() {
    baseURL := "https://api.microlink.io"

    u, err := url.Parse(baseURL)
    if err != nil {
        panic(err)
    }
    q := u.Query()
    q.Set("url", "https://example.com")
    q.Set("data.title", "[object Object],[object Object],[object Object]")
    u.RawQuery = q.Encode()

    req, err := http.NewRequest("GET", u.String(), nil)
    if err != nil {
        panic(err)
    }

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, err := io.ReadAll(resp.Body)
    if err != nil {
        panic(err)
    }

    fmt.Println(string(body))
}
```

```javascript
importmqlfrom'@microlink/mql'

const{data}=awaitmql('https://example.com',{

data:{

title:[

{

selector:'meta[property="og:title"]',

attr:"content"

},

{

selector:"title",

attr:"text"

},

{

selector:"h1",

attr:"text"

}

]

}

})
```

Try multiple selectors in order until one succeeds.

You can read the [Microlink Query Language](https://microlink.io/docs/mql/getting-started/overview) documentation to learn more about defining data extraction rules.

Last updated on March 17, 2026

[Edit on GitHub](https://github.com/microlinkhq/www/blob/master/src/content/docs/api/parameters/data.md)