attr

Type:
<string> | <string[]>

Default: 'html'
Values:
| | 'html' | 'innerHTML' | 'outerHTML' | 'text' | 'textContent' | 'innerText' | 'val'
It specifies which attribute should be picked over the matched selector:
const mql = require('@microlink/mql')

const github = username =>
  mql(`https://github.com/${username}`, {
    data: {
      avatar: {
        selector: 'meta[property="og:image"]:not([content=""])',
        attr: 'content',
        type: 'image'
      }
    }
  })

const username = 'kikobeats'
const { response, data } = await github(username)

console.log(
  `GitHub avatar for @${username}: ${data.avatar.url} (${data.avatar.size_pretty})`
)
Any is supported, plus the following special cases:
  • 'text': Returns the combined text content, including its descendants, by removing leading, trailing, and repeated whitespace from a string.
  • 'html': Get the HTML content of the matched selector. (Same as 'innerHTML').
  • 'val': Get the current value of the matched selector, oriented for select or input fields.
If you specifiy more than one value, they will be used as fallback values:
const mql = require('@microlink/mql')

const github = username =>
  mql(`https://github.com/${username}`, {
    data: {
      avatar: [
        {
          selector: 'meta[name="twitter:image:src"]:not([content=""])',
          attr: 'content',
          type: 'image'
        },
        {
          selector: 'meta[property="og:image"]:not([content=""])',
          attr: 'content',
          type: 'image'
        }
      ]
    }
  })

const username = 'kikobeats'
const { response, data } = await github(username)

console.log(
  `GitHub avatar for @${username}: ${data.avatar.url} (${data.avatar.size_pretty})`
)
The first attribute that resolve the value will be used.