Skip to content

links

Sweeps every a element and returns each href as an absolute, deduped URL:
const links = await microlink.links('https://example.com')
Relative hrefs are resolved against the page URL, and values that don't parse as a URL — mailto:, javascript:, empty anchors — are dropped by the 'url' type.

Options

Override the default rule of selectorAll: 'a', attr: 'href', and type: 'url' with selectorAll, selector, attr, or type.

Examples

Only the navigation links:
const links = await microlink.links('https://example.com', {
  selectorAll: 'nav a'
})
Links on a client-side rendered page:
const links = await microlink.links('https://app.example.com', {
  prerender: true,
  waitForSelector: 'main a'
})
External links only, filtered on your side:
const { hostname } = new URL('https://example.com')
const links = await microlink.links('https://example.com')
const external = links.filter(link => new URL(link).hostname !== hostname)
For each link's text alongside its URL, write a nested rule with extract.