# Facebook Comments Scraper (`datavoyantlab/facebook-comments-scraper`) Actor

Extract Facebook comments from any post, page, or group. Download hundreds of comments with user data and engagement metrics in JSON, CSV, or Excel format.

- **URL**: https://apify.com/datavoyantlab/facebook-comments-scraper.md
- **Developed by:** [DataVoyantLab](https://apify.com/datavoyantlab) (community)
- **Categories:** Social media, Lead generation
- **Stats:** 659 total users, 11 monthly users, 97.1% runs succeeded, 11 bookmarks
- **User rating**: 5.00 out of 5 stars

## Pricing

$25.00/month + usage

To use this Actor, you pay a monthly rental fee to the developer. The rent is subtracted from your prepaid usage every month after the free trial period.You also pay for the Apify platform usage, which gets cheaper the higher Apify subscription plan you have.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#rental-actors

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

### Facebook Comments Scraper

The **Facebook Comments Scraper** is a powerful tool designed to help you easily collect comments from any Facebook post, whether it's from accounts, public pages, group posts, or videos.

#### What Does It Extract?

Get comprehensive details such as comment text, author information, timestamps, like counts, number of replies, and more.


#### Example Output Data

Here’s a sample of the structured output data you can expect:

```json
{
  "id": "847615209483751_392847561234567",
  "created_at": 1729892140,
  "message": "We need to invest in renewable energy and sustainable infrastructure to create jobs and protect our environment for future generations. The time for action is now!",
  "url": "https://www.facebook.com/nytimes/posts/pfbid03KmLqPw8nVt5gXjDs9YrNmE4hF3vQ7RwBp4m2WSt8k9uLxMv86ZnTcPdhRxNzLt4xl?comment_id=392847561234567",
  "comment_count": 12,
  "reaction_count": "45",
  "attachments": [],
  "text_entities": [],
  "is_post_author": false,
  "author": {
    "id": "856923441",
    "is_verified": false,
    "name": "Sarah Chen",
    "gender": "FEMALE",
    "profile_url": "https://www.facebook.com/sarahchen2024",
    "profile_image_url": "https://scontent-atl3-1.xx.fbcdn.net/v/t39.30808-1/384756291_10162830467892345_2947583691234567891_n.jpg?stp=cp0_dst-jpg_s32x32&_nc_cat=104&ccb=1-7&_nc_sid=50d2ac&_nc_ohc=Yx8nKpL2MYAQ7kPwrT9TCCg&_nc_ht=scontent-atl3-1.xx&_nc_gid=B-KWj4Ydz8f3H1XkwyZfsTU&oh=00_AYBMktsp1p4ZbcdqBUr2kwl9T5K8gH1vF82hdk22z48SQQ&oe=6721DF8C",
    "short_name": "Sarah",
    "work_info": null
  }
}
````

#### How to Use the Facebook Comments Scraper

To use the **Facebook Comments Scraper**, you need to provide the following inputs:

1. **Facebook Post URL**: Provide the URL of the post you want to scrape comments from.
   - Example: `https://www.facebook.com/natgeo/posts/pfbid02stjvzcsfWYcQ9EVhNuCdSRnFCKwmJdi5rE9RFPwMoLbpH4uj8mNUBTbS6QCH7eYDl`

2. **Cookies** (optional): Passing cookies allows access to more comments and posts. To obtain cookies:
   - Install the [Cookie-Editor](https://chromewebstore.google.com/detail/cookie-editor/hlkenndednhfkekhgcdicdfddnkalmdm) Chrome extension.
   - Log in to your Facebook account, open the extension, and export the Facebook cookies in JSON format.

3. **Maximum Number of Items**: Set a limit on the number of comments to scrape. Leave it empty to scrape all comments.

4. **Sort Type**: Choose how the comments should be sorted (most relevant, newest, or all comments).

5. **Min and Max Delay**: Specify the minimum and maximum delay between requests to avoid getting blocked.

6. **Proxy Configuration**: Use a proxy that matches your Facebook account’s location to avoid detection.

# Actor input Schema

## `url` (type: `string`):

Post to scrape comments from.

## `cookies` (type: `array`):

Passing cookies is optional but allows access to additional comments and posts. To do this, install the [Cookie-Editor](https://chromewebstore.google.com/detail/cookie-editor/hlkenndednhfkekhgcdicdfddnkalmdm) Chrome extension. Log in to your facebook.com account, open the extension, and export your facebook.com cookies in json. Paste the exported cookie data here.

## `max_items` (type: `integer`):

Keep it empty to scrape all comments.

## `sort_type` (type: `string`):

Choose the sorting type of the comments.

## `min_delay` (type: `integer`):

Choose a reasonable value to avoid getting blocked.

## `max_delay` (type: `integer`):

Choose a reasonable value to avoid getting blocked.

## `proxy` (type: `object`):

Use a proxy server that matches your Facebook account's country to avoid getting blocked.

## Actor input object example

```json
{
  "url": "https://www.facebook.com/natgeo/posts/pfbid02stjvzcsfWYcQ9EVhNuCdSRnFCKwmJdi5rE9RFPwMoLbpH4uj8mNUBTbS6QCH7eYDl",
  "sort_type": "all",
  "min_delay": 3,
  "max_delay": 5,
  "proxy": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ],
    "apifyProxyCountry": "US"
  }
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

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

// Prepare Actor input
const input = {
    "url": "https://www.facebook.com/natgeo/posts/pfbid02stjvzcsfWYcQ9EVhNuCdSRnFCKwmJdi5rE9RFPwMoLbpH4uj8mNUBTbS6QCH7eYDl",
    "sort_type": "all",
    "min_delay": 3,
    "max_delay": 5,
    "proxy": {
        "useApifyProxy": true,
        "apifyProxyGroups": [
            "RESIDENTIAL"
        ],
        "apifyProxyCountry": "US"
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("datavoyantlab/facebook-comments-scraper").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "url": "https://www.facebook.com/natgeo/posts/pfbid02stjvzcsfWYcQ9EVhNuCdSRnFCKwmJdi5rE9RFPwMoLbpH4uj8mNUBTbS6QCH7eYDl",
    "sort_type": "all",
    "min_delay": 3,
    "max_delay": 5,
    "proxy": {
        "useApifyProxy": True,
        "apifyProxyGroups": ["RESIDENTIAL"],
        "apifyProxyCountry": "US",
    },
}

# Run the Actor and wait for it to finish
run = client.actor("datavoyantlab/facebook-comments-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "url": "https://www.facebook.com/natgeo/posts/pfbid02stjvzcsfWYcQ9EVhNuCdSRnFCKwmJdi5rE9RFPwMoLbpH4uj8mNUBTbS6QCH7eYDl",
  "sort_type": "all",
  "min_delay": 3,
  "max_delay": 5,
  "proxy": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ],
    "apifyProxyCountry": "US"
  }
}' |
apify call datavoyantlab/facebook-comments-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=datavoyantlab/facebook-comments-scraper",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Facebook Comments Scraper",
        "description": "Extract Facebook comments from any post, page, or group. Download hundreds of comments with user data and engagement metrics in JSON, CSV, or Excel format.",
        "version": "1.0",
        "x-build-id": "1NVETlmQfPWUlYK53"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/datavoyantlab~facebook-comments-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-datavoyantlab-facebook-comments-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/datavoyantlab~facebook-comments-scraper/runs": {
            "post": {
                "operationId": "runs-sync-datavoyantlab-facebook-comments-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/datavoyantlab~facebook-comments-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-datavoyantlab-facebook-comments-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "url",
                    "proxy"
                ],
                "properties": {
                    "url": {
                        "title": "Facebook Post URL",
                        "type": "string",
                        "description": "Post to scrape comments from."
                    },
                    "cookies": {
                        "title": "Cookies",
                        "type": "array",
                        "description": "Passing cookies is optional but allows access to additional comments and posts. To do this, install the [Cookie-Editor](https://chromewebstore.google.com/detail/cookie-editor/hlkenndednhfkekhgcdicdfddnkalmdm) Chrome extension. Log in to your facebook.com account, open the extension, and export your facebook.com cookies in json. Paste the exported cookie data here."
                    },
                    "max_items": {
                        "title": "Total scraped items to not exceed",
                        "type": "integer",
                        "description": "Keep it empty to scrape all comments."
                    },
                    "sort_type": {
                        "title": "Sort type",
                        "enum": [
                            "most_relevant",
                            "newest",
                            "all"
                        ],
                        "type": "string",
                        "description": "Choose the sorting type of the comments."
                    },
                    "min_delay": {
                        "title": "Min delay between requests in seconds",
                        "type": "integer",
                        "description": "Choose a reasonable value to avoid getting blocked.",
                        "default": 3
                    },
                    "max_delay": {
                        "title": "Max delay between requests in seconds",
                        "type": "integer",
                        "description": "Choose a reasonable value to avoid getting blocked.",
                        "default": 5
                    },
                    "proxy": {
                        "title": "Proxy Configuration",
                        "type": "object",
                        "description": "Use a proxy server that matches your Facebook account's country to avoid getting blocked."
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
