microlink logo

Microlink Recipe

Interact with imdb.com

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

const imdb = async (url, opts) => {
  const result = await mql(url, {
    data: {
      director: {
        selector: '.credit_summary_item:first a',
        type: 'text',
      },
      writer: {
        selector: '.credit_summary_item:nth-child(2) a',
        type: 'text',
      },
      duration: {
        selector: '.title_wrapper time',
        type: 'text',
      },
      release: {
        selector: '.title_wrapper a:nth-child(7)',
        type: 'text',
      },
      rating: {
        selector: 'span[itemprop="ratingValue"]',
        type: 'text',
      },
      ratingCount: {
        selector: 'span[itemprop="ratingCount"]',
        type: 'text',
      },
    },
    ...opts,
  })

  if (result.data.rating) result.data.rating += ' of 10'
  if (result.data.release) result.data.release = result.data.release.trim()
  if (result.data.duration) result.data.duration = result.data.duration.trim()
  return result
}

const result = await imdb('https://www.imdb.com/title/tt1853728/')
console.log(result)