microlink logo

Microlink Recipe

Interact with instagram.com

instagram.js
const mql = require('@microlink/mql')

const instagram = async (url, opts) => {
  const result = await mql(url, {
    data: {
      avatar: {
        selector: 'meta[property="og:image"]',
        attr: 'content',
        type: 'image',
      },
      stats: {
        selector: 'meta[property="og:description"]',
        attr: 'content',
      },
    },
    ...opts,
  })

  if (result.data.stats) {
    result.data.stats = result.data.stats.split(' - ')[0]
    result.data.stats = result.data.stats.split(', ')
    result.data.stats = result.data.stats.reduce((acc, info) => {
      const [value, key] = info.split(' ')
      return { ...acc, [key.toLowerCase()]: value }
    }, {})
  }

  return result
}

const result = await instagram('https://www.instagram.com/willsmith')

mql.render(result)