Actor picture

Facebook Pages Scraper

pocesar/facebook-pages-scraper

Facebook scraping tool to crawl and extract data from Facebook Pages. Our fully updated FB scraper downloads posts, likes, comments, reviews, contact details, social media profiles, address, and all public data from Facebook Pages. Download data as JSON, CSV, Excel, XML, and more.

Author's avatarPaulo Cesar
  • Modified
  • Used by4,802 users
  • Used367,452 times
Actor picture
Facebook Pages Scraper

To run the code examples, you need to have an Apify account. Replace <YOUR_API_TOKEN> in the code with your API token.

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://www.facebook.com/apifytech/"
        }
    ],
    language: "en-US",
    searchLimit: 10,
    maxPosts: 3,
    maxPostComments: 15,
    maxReviews: 3,
    proxyConfiguration: {
        useApifyProxy: true,
        apifyProxyGroups: [
            "RESIDENTIAL"
        ]
    },
    extendOutputFunction: ({ data, item, customData, Apify }) => {
        return item;
    },
    extendScraperFunction: async ({ page, LABELS, label, request, username, map, fns, customData, Apify }) => {
        if (label === 'HANDLE') {
            // this is inside the handlePageFunction
        } else if (label === 'SETUP') {
            // before starting the crawler
        } else if (label === 'FINISH') {
            // after finishing the crawler
        }
    },
    customData: {}
};

(async () => {
    // Run the actor and wait for it to finish
    const run = await client.actor("pocesar/facebook-pages-scraper").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);
    });
})();