selector

Type: string|string[]
Values:
It defines the first HTML element you want to get from the HTML of the target url. It's equivalent to .
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>kikobeats.com</title>
  </head>
  <body>
    <h1>
      Hey, I'm <span>Kiko Beats</span>, a millennial doing stuff on internet.
    </h1>
    <img id="avatar" src="https://kikobeats.com/images/avatar-glitch.jpg" />
  </body>
</html>
const mql = require('@microlink/mql')
const { data } mql(`https://kikobeats.com`, {
  data: {
    avatar: {
      selector: '#avatar',
      attr: 'src'
    }
  }
})
{
  "data": {
    "avatar": "https://kikobeats.com/images/avatar-glitch.jpg"
  }
}

`selector` should be specified for getting data.

You can specify any , like:
  • An HTML tag (e.g., img).
  • An CSS class or pseudo class, id or data-attribute (e.g., #avatar).
  • A combination of both (e.g., img:first).
If you pass a collection of selectors, they are considered as fallbacks values.
const mql = require('@microlink/mql')
const {data } mql(`https://twitter.com/${username}`, {
  data: {
    avatar: {
      selector: ['#avatar', 'img:first']
    }
  }
})

Using mulitple selector makes the data rule more generic.

The position into the collection matters: The first data rule that returns a truthy value after applying type will be used, not being applying the rest of selectors.

selector

Type: string|string[]
Values:
It defines the first HTML element you want to get from the HTML of the target url. It's equivalent to .
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>kikobeats.com</title>
  </head>
  <body>
    <h1>
      Hey, I'm <span>Kiko Beats</span>, a millennial doing stuff on internet.
    </h1>
    <img id="avatar" src="https://kikobeats.com/images/avatar-glitch.jpg" />
  </body>
</html>
const mql = require('@microlink/mql')
const { data } mql(`https://kikobeats.com`, {
  data: {
    avatar: {
      selector: '#avatar',
      attr: 'src'
    }
  }
})
{
  "data": {
    "avatar": "https://kikobeats.com/images/avatar-glitch.jpg"
  }
}

`selector` should be specified for getting data.

You can specify any , like:
  • An HTML tag (e.g., img).
  • An CSS class or pseudo class, id or data-attribute (e.g., #avatar).
  • A combination of both (e.g., img:first).
If you pass a collection of selectors, they are considered as fallbacks values.
const mql = require('@microlink/mql')
const {data } mql(`https://twitter.com/${username}`, {
  data: {
    avatar: {
      selector: ['#avatar', 'img:first']
    }
  }
})

Using mulitple selector makes the data rule more generic.

The position into the collection matters: The first data rule that returns a truthy value after applying type will be used, not being applying the rest of selectors.

By using this website you agree to ourprivacy.