Playwright Scraper avatar

Playwright Scraper

Try for free

No credit card required

View all Actors
Playwright Scraper

Playwright Scraper

apify/playwright-scraper
Try for free

No credit card required

Crawls websites with the headless Chromium, Chrome, or Firefox browser and Playwright library using a provided server-side Node.js code. Supports both recursive crawling and a list of URLs. Supports login to a website.

Do you want to learn more about this Actor?

Get a demo

You can access the Playwright Scraper programmatically from your own JavaScript applications by using the Apify API. You can also choose the language preference from below. To use the Apify API, you’ll need an Apify account and your API token, found in Integrations settings in Apify Console.

1import { ApifyClient } from 'apify-client';
2
3// Initialize the ApifyClient with your Apify API token
4// Replace the '<YOUR_API_TOKEN>' with your token
5const client = new ApifyClient({
6    token: '<YOUR_API_TOKEN>',
7});
8
9// Prepare Actor input
10const input = {
11    "startUrls": [
12        {
13            "url": "https://crawlee.dev"
14        }
15    ],
16    "globs": [
17        {
18            "glob": "https://crawlee.dev/*/*"
19        }
20    ],
21    "pseudoUrls": [],
22    "excludes": [
23        {
24            "glob": "/**/*.{png,jpg,jpeg,pdf}"
25        }
26    ],
27    "linkSelector": "a",
28    "pageFunction": async function pageFunction(context) {
29        const { page, request, log } = context;
30        const title = await page.title();
31        log.info(`URL: ${request.url} TITLE: ${title}`);
32        return {
33            url: request.url,
34            title
35        };
36    },
37    "proxyConfiguration": {
38        "useApifyProxy": true
39    },
40    "initialCookies": [],
41    "launcher": "chromium",
42    "waitUntil": "networkidle",
43    "preNavigationHooks": `// We need to return array of (possibly async) functions here.
44        // The functions accept two arguments: the "crawlingContext" object
45        // and "gotoOptions".
46        [
47            async (crawlingContext, gotoOptions) => {
48                const { page } = crawlingContext;
49                // ...
50            },
51        ]`,
52    "postNavigationHooks": `// We need to return array of (possibly async) functions here.
53        // The functions accept a single argument: the "crawlingContext" object.
54        [
55            async (crawlingContext) => {
56                const { page } = crawlingContext;
57                // ...
58            },
59        ]`,
60    "customData": {}
61};
62
63// Run the Actor and wait for it to finish
64const run = await client.actor("apify/playwright-scraper").call(input);
65
66// Fetch and print Actor results from the run's dataset (if any)
67console.log('Results from dataset');
68console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
69const { items } = await client.dataset(run.defaultDatasetId).listItems();
70items.forEach((item) => {
71    console.dir(item);
72});
73
74// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

Playwright Scraper API in JavaScript

The Apify API client for JavaScript is the official library that allows you to use Playwright Scraper API in JavaScript or TypeScript, providing convenience functions and automatic retries on errors.

Install the apify-client

npm install apify-client

Other API clients include:

Developer
Maintained by Apify
Actor metrics
  • 63 monthly users
  • 14 stars
  • 99.4% runs succeeded
  • 21 days response time
  • Created in Aug 2022
  • Modified 3 months ago