type
Type:
Default: 'auto'
Values:
<string> | <string[]>
Default: 'auto'
Values:
'audio' | 'author' | 'auto' | 'boolean' | 'date' | 'description' | 'email' | 'image' | 'ip' | 'lang' | 'logo' | 'number' | 'object' | 'publisher' | 'regexp' | 'string' | 'title' | 'url' | 'video'
It defines how the value extracted should be considered.
const mql = require('@microlink/mql')
const productHunt = id =>
mql(`https://www.producthunt.com/posts/${id}`, {
data: {
name: {
selector: 'h1 a',
attr: 'text',
type: 'string'
},
upvotes: {
selector: '.bigButtonCount_10448',
attr: 'text',
type: 'string'
}
}
})
const productSlug = 'microlink-2-0'
const { data } = await productHunt(productSlug)
console.log(`'${data.name}' has ${data.upvotes} upvotes`)The data shape ensures that the extracted value will only be considered as valid when it's of the declared shape.