Skip to content

selectorAll

Type:
<string> | <string[]>

Values: CSS selector
It's the same as selector but it returns a collection of results, being equivalent to Document.querySelectorAll():
import createClient from 'microlink.io'

const microlink = createClient()

const hackerNews = () =>
  microlink.extract('https://news.ycombinator.com/', {
    posts: {
      selectorAll: '.athing',
      attr: {
        title: {
          type: 'title',
          selector: '.titleline > a',
          attr: 'text'
        },
        url: {
          type: 'url',
          selector: '.titleline > a',
          attr: 'href'
        }
      }
    }
  })

const { posts } = await hackerNews()

console.log('latest hacker news posts:', posts)
Without a nested attr, each match contributes one plain value, which is how links and the other sweep methods work:
const { links } = await microlink.extract('https://news.ycombinator.com/', {
  links: {
    selectorAll: '.titleline > a',
    attr: 'href',
    type: 'url'
  }
})

console.log(links) // => ['https://…', 'https://…', …]