Extract links from a webpage
Bun’s HTMLRewriter API can be used to efficiently extract links from HTML content. It works by chaining together CSS selectors to match the elements, text, and attributes you want to process. Here is an example of how to extract links from a webpage. You can pass.transform a Response, Blob, or string.
Convert relative URLs to absolute
When scraping websites, you often want to convert relative URLs (like/docs) to absolute URLs. Here’s how to handle URL resolution:
See Docs > API > HTMLRewriter for complete documentation on HTML transformation with Bun.