href_finder
v1.0.1
Published
Extract URLs from HTML and XML sitemap content
Readme
href_finder
href_finder is a lightweight Node.js utility to extract URLs from HTML content and XML sitemaps without using any external dependencies.
Files
HrefFinder.js— main entry point that provides a clean APIUrlExtractor.js— extracts URLs from HTML stringsSitemapExtractor.js— extracts URLs from XML sitemap strings
Usage
Example usage in a Node.js script:
import { HrefFinder } from './HrefFinder.js';
import fs from 'fs';
// Extract URLs from HTML
const html = fs.readFileSync('example.html', 'utf8');
const htmlUrls = HrefFinder.fromHtml(html);
console.log(htmlUrls);
// Extract URLs from Sitemap XML
const sitemap = fs.readFileSync('sitemap.xml', 'utf8');
const sitemapUrls = HrefFinder.fromSitemap(sitemap);
console.log(sitemapUrls);How It Works
UrlExtractor.jssearches for URLs insidehref="",src=""attributes and raw text within the HTML string.SitemapExtractor.jsparses XML sitemap content and extracts URLs from<loc>tags.HrefFinder.jsprovides two static methods:fromHtml(htmlString)fromSitemap(xmlString)
Each method returns a list of extracted URLs.
Requirements
- Node.js v14 or higher
- No third-party modules required
License
MIT License.
