The crawler is configured using a Config object that defines the crawl scope, extraction rules, and output constraints. You can provide a starting URL (or a sitemap), define patterns for matching or excluding links, and specify a CSS selector to extract specific text content from pages.
Key Configuration Options
url: The starting URL for the crawl. If a sitemap URL is provided, the crawler will follow all links within that sitemap.match: A string or array of strings representing patterns to match against links for subsequent crawling.exclude: A string or array of strings representing patterns to exclude from crawling.selector: A CSS selector used to grab the inner text from the page.maxPagesToCrawl: The maximum number of pages to visit (default is 50).outputFileName: The name of the file where the crawled data will be saved.cookie: An optional single cookie object or an array of cookie objects (each with name and value) to be set during the crawl (e.g., for handling cookie consent).onVisitPage: An optional async function called for every page found. It receives an object containing the Playwright page and a pushData function to manually add data to the output.resourceExclusions: An optional array of file extensions to exclude from crawling.maxFileSize: The maximum file size in megabytes to include in the output.maxTokens: The maximum number of tokens to include in the output.waitForSelectorTimeout: An optional timeout (in milliseconds) for waiting for a selector to appear.
const config: Config = {
url: 'https://www.builder.io/c/docs/developers',
match: 'https://www.builder.io/c/docs/**',
exclude: 'https://www.builder.io/c/docs/exclude-me/**',
selector: '.docs-builder-container',
maxPagesToCrawl: 50,
outputFileName: 'output.json',
cookie: [
{ name: 'consent', value: 'true' }
],
onVisitPage: async ({ page, pushData }) => {
// Custom logic per page
await pushData({ custom: 'data' });
}
};