Parsed HTML document or raw HTML string
OptionalbaseUrl: string | URL | nullBase URL for resolving relative links and determining internal/external
Extraction options for filtering and categorization
Links metadata with categorized links
Extracts all <a href> links with comprehensive metadata and filtering options.
Perfect for crawlers, SEO analysis, and link discovery.
Features:
// With parsed document (recommended for multiple extractions)
const doc = parseHTML(htmlString);
const links = extractLinks(doc, 'https://example.com');
// Or directly with HTML string
const links = extractLinks(htmlString, 'https://example.com');
// Get all internal links (same origin)
console.log(links.internal);
// Get external links excluding nofollow
const linksNoFollow = extractLinks(htmlString, 'https://example.com', {
scope: 'external',
excludeRel: ['nofollow']
});
Extract links from HTML.