### Initialize a new Crawlee project Source: https://crawlee.dev Use the CLI to scaffold a new project for either JavaScript or Python environments. ```bash npx crawlee create my-crawler ``` ```bash uvx 'crawlee[cli]' create my-crawler ``` -------------------------------- ### Implement a Playwright crawler Source: https://crawlee.dev A basic implementation of PlaywrightCrawler to visit a URL, extract the page title, and manage the crawl queue. ```javascript import { PlaywrightCrawler } from 'crawlee'; // PlaywrightCrawler crawls the web using a headless browser controlled by the Playwright library. const crawler = new PlaywrightCrawler({ // Use the requestHandler to process each of the crawled pages. async requestHandler({ request, page, enqueueLinks, pushData, log }) { const title = await page.title(); log.info(`Title of ${request.loadedUrl} is '${title}'`); // Save results as JSON to `./storage/datasets/default` directory. await pushData({ title, url: request.loadedUrl }); // Extract links from the current page and add them to the crawling queue. await enqueueLinks(); }, // Uncomment this option to see the browser window. // headless: false, // Comment this option to scrape the full website. maxRequestsPerCrawl: 20, }); // Add first URL to the queue and start the crawl. await crawler.run(['https://crawlee.dev']); // Export the whole dataset to a single file in `./result.csv`. await crawler.exportData('./result.csv'); // Or work with the data directly. const data = await crawler.getData(); console.table(data.items); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.