Actor picture

Puppeteer Improved Inputs Scraper

barry8schneider/puppeteer20191228

Add the following options to inputs: Use Live View, Inject Query, and Inject Underscore

No credit card required

Author's avatarBarry Schneider
  • Modified
  • Users19
  • Runs109
Actor picture

Puppeteer Improved Inputs Scraper

To run the code examples, you need to have an Apify account. Replace <YOUR_API_TOKEN> in the code with your API token. For a more detailed explanation, please read about running actors via the API in Apify Docs.

const { ApifyClient } = require('apify-client');

// Initialize the ApifyClient with API token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare actor input
const input = {
    "startUrls": [
        {
            "url": "https://apify.com"
        }
    ],
    "pseudoUrls": [
        {
            "purl": "https://apify.com[(/[\\w-]+)?]"
        }
    ],
    "linkSelector": "a",
    "proxyConfiguration": {
        "useApifyProxy": false
    },
    "customData": {},
    "pageFunction": async function pageFunction(context) {
        const { page, request, log } = context;
        const title = await page.title();
        log.info(`URL: ${request.url} TITLE: ${title}`);
        return {
            url: request.url,
            title
        };
    },
    "preGotoFunction": async function preGotoFunction({ request, page, Apify }) {
        /* add your pre-navigation logic here, if needed */
    },
    "initialCookies": [],
    "waitUntil": [
        "networkidle2"
    ]
};

(async () => {
    // Run the actor and wait for it to finish
    const run = await client.actor("barry8schneider/puppeteer20191228").call(input);

    // Fetch and print actor results from the run's dataset (if any)
    console.log('Results from dataset');
    const { items } = await client.dataset(run.defaultDatasetId).listItems();
    items.forEach((item) => {
        console.dir(item);
    });
})();