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

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 mode

Node.js

Python

curl

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://apify.com"
13        }
14    ],
15    "pseudoUrls": [
16        {
17            "purl": "https://apify.com[(/[\\w-]+)?]"
18        }
19    ],
20    "linkSelector": "a",
21    "pageFunction": async function pageFunction(context) {
22        const { page, request, log } = context;
23        const title = await page.title();
24        log.info(`URL: ${request.url} TITLE: ${title}`);
25        return {
26            url: request.url,
27            title
28        };
29    },
30    "proxyConfiguration": {
31        "useApifyProxy": false
32    },
33    "customData": {},
34    "initialCookies": [],
35    "preGotoFunction": async function preGotoFunction({ request, page, Apify }) {
36        /* add your pre-navigation logic here, if needed */
37    }
38};
39
40(async () => {
41    // Run the Actor and wait for it to finish
42    const run = await client.actor("apify/puppeteer-scraper").call(input);
43
44    // Fetch and print Actor results from the run's dataset (if any)
45    console.log('Results from dataset');
46    const { items } = await client.dataset(run.defaultDatasetId).listItems();
47    items.forEach((item) => {
48        console.dir(item);
49    });
50})();
Developer
Community logoMaintained by Community
Actor metrics
  • 2 monthly users
  • 34.5% runs succeeded
  • Created in Apr 2019
  • Modified about 5 years ago
Categories

You might also like these Actors