Puppeteer Scraper avatar
Puppeteer Scraper
Try for free

No credit card required

View all Actors
Puppeteer Scraper

Puppeteer Scraper

apify/puppeteer-scraper
Try for free

No credit card required

Crawls websites with the headless Chrome and Puppeteer library using a provided server-side Node.js code. This crawler is an alternative to apify/web-scraper that gives you finer control over the process. Supports both recursive crawling and list of URLs. Supports login to website.

The code examples below show how to run the Actor and get its results. To run the code, you need to have an Apify account. Replace <YOUR_API_TOKEN> in the code with your API token, which you can find under Settings > Integrations in Apify Console. Learn more

1import { ApifyClient } from 'apify-client';
2
3// Initialize the ApifyClient with your Apify API token
4const client = new ApifyClient({
5    token: '<YOUR_API_TOKEN>',
6});
7
8// Prepare Actor input
9const input = {
10    "startUrls": [
11        {
12            "url": "https://crawlee.dev"
13        }
14    ],
15    "globs": [
16        {
17            "glob": "https://crawlee.dev/*/*"
18        }
19    ],
20    "pseudoUrls": [],
21    "excludes": [
22        {
23            "glob": "/**/*.{png,jpg,jpeg,pdf}"
24        }
25    ],
26    "linkSelector": "a",
27    "pageFunction": async function pageFunction(context) {
28        const { page, request, log } = context;
29        const title = await page.title();
30        log.info(`URL: ${request.url} TITLE: ${title}`);
31        return {
32            url: request.url,
33            title
34        };
35    },
36    "proxyConfiguration": {
37        "useApifyProxy": true
38    },
39    "initialCookies": [],
40    "waitUntil": [
41        "networkidle2"
42    ],
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(async () => {
64    // Run the Actor and wait for it to finish
65    const run = await client.actor("apify/puppeteer-scraper").call(input);
66
67    // Fetch and print Actor results from the run's dataset (if any)
68    console.log('Results from dataset');
69    console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
70    const { items } = await client.dataset(run.defaultDatasetId).listItems();
71    items.forEach((item) => {
72        console.dir(item);
73    });
74})();
75
76// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs
Developer
Maintained by Apify
Actor metrics
  • 353 monthly users
  • 0 stars
  • 99.8% runs succeeded
  • 28 days response time
  • Created in Apr 2019
  • Modified about 2 months ago