TypeScript Playwright scraper
A Playwright-based browser scraper supporting multiple browsers and contexts.
src/main.ts
src/routes.ts
1/**2 * This template is a production ready boilerplate for developing with `PlaywrightCrawler`.3 * Use this to bootstrap your projects using the most up-to-date code.4 * If you're looking for examples or want to learn more, see README.5 */6
7// For more information, see https://crawlee.dev8import { PlaywrightCrawler } from '@crawlee/playwright';9// For more information, see https://docs.apify.com/sdk/js10import { Actor } from 'apify';11
12// this is ESM project, and as such, it requires you to specify extensions in your relative imports13// read more about this here: https://nodejs.org/docs/latest-v18.x/api/esm.html#mandatory-file-extensions14// note that we need to use `.js` even when inside TS files15import { router } from './routes.js';16
17interface Input {18 startUrls: {19 url: string;20 method?: 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'TRACE' | 'OPTIONS' | 'CONNECT' | 'PATCH';21 headers?: Record<string, string>;22 userData: Record<string, unknown>;23 }[];24 maxRequestsPerCrawl: number;25}26
27// Initialize the Apify SDK28await Actor.init();29
30// Structure of input is defined in input_schema.json31const { startUrls = ['https://apify.com'], maxRequestsPerCrawl = 100 } =32 (await Actor.getInput<Input>()) ?? ({} as Input);33
34// `checkAccess` flag ensures the proxy credentials are valid, but the check can take a few hundred milliseconds.35// Disable it for short runs if you are sure your proxy configuration is correct36const proxyConfiguration = await Actor.createProxyConfiguration({ checkAccess: true });37
38const crawler = new PlaywrightCrawler({39 proxyConfiguration,40 maxRequestsPerCrawl,41 requestHandler: router,42 launchContext: {43 launchOptions: {44 args: [45 '--disable-gpu', // Mitigates the "crashing GPU process" issue in Docker containers46 ],47 },48 },49});50
51await crawler.run(startUrls);52
53// Exit successfully54await Actor.exit();This template is a production ready boilerplate for developing an Actor with PlaywrightCrawler. Use this to bootstrap your projects using the most up-to-date code.
We decided to split Apify SDK into two libraries, Crawlee and Apify SDK v3. Crawlee will retain all the crawling and scraping-related tools and will always strive to be the best web scraping library for its community. At the same time, Apify SDK will continue to exist, but keep only the Apify-specific features related to building Actors on the Apify platform. Read the upgrading guide to learn about the changes.
If you're looking for examples or want to learn more visit:
- Crawlee + Apify Platform guide
- Documentation and examples
- Node.js tutorials in Academy
- Scraping single-page applications with Playwright
- How to scale Puppeteer and Playwright
- Integration with Zapier , Make, GitHub, Google Drive and other apps
- Video guide on getting scraped data using Apify API
- A short guide on how to build web scrapers using code templates:
TypeScript Cheerio crawler
A fast HTTP crawler that extracts data from every page. Good for simple sites like blogs, news, or product listings, but it can't run client-side JavaScript.
TypeScript one-page scraper
Get data from one web page with Cheerio. The simplest way to start scraping.
TypeScript Puppeteer scraper
A headless Chrome scraper that renders JavaScript before extracting data. Good for social feeds, dashboards, or single-page apps.
TypeScript Camoufox scraper
A Firefox-based browser built to look like a real user and bypass bot protection.
Playwright test runner
An automated browser test runner with results you can access via API.
Empty TypeScript Actor
An Actor with the Apify SDK set up, so you can build any tool you need.