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. This is a simple 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.