Back to template gallery

Crawlee + Playwright + Chrome

Web scraper example with Crawlee, Playwright and headless Chrome. Playwright is more modern, user-friendly and harder to block than Puppeteer.

Language

javascript

Tools

nodejs

crawlee

playwright

Use cases

Web scraping

src/main.js

src/routes.js

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://docs.apify.com/sdk/js
8import { Actor } from 'apify';
9// For more information, see https://crawlee.dev
10import { PlaywrightCrawler } from 'crawlee';
11// this is ESM project, and as such, it requires you to specify extensions in your relative imports
12// read more about this here: https://nodejs.org/docs/latest-v18.x/api/esm.html#mandatory-file-extensions
13import { router } from './routes.js';
14
15// Initialize the Apify SDK
16await Actor.init();
17
18const {
19    startUrls = ['https://crawlee.dev'],
20} = await Actor.getInput() ?? {};
21
22const proxyConfiguration = await Actor.createProxyConfiguration();
23
24const crawler = new PlaywrightCrawler({
25    proxyConfiguration,
26    requestHandler: router,
27});
28
29await crawler.run(startUrls);
30
31// Exit successfully
32await Actor.exit();

PlaywrightCrawler template

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.

Resources

If you're looking for examples or want to learn more visit:

Already have a solution in mind?

Sign up for a free Apify account and deploy your code to the platform in just a few minutes! If you want a head start without coding it yourself, browse our Store of existing solutions.