attr
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
HTML attribute
is supported, keeping in mind three special values:- 'text': Get the combined text content, including their descendants.
- 'val': Get the current value of the matched selector.
- 'html': Get the HTML content of the matched selector.
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})` )