# Facebook Ad Library Scraper - Competitor Ads & Creatives (`fascinating_lentil/facebook-ad-library-scraper`) Actor

Scrape ads from the public Facebook Ad Library. Extract ad creatives, text, headlines, spend ranges, impressions, targeting info, and more.

- **URL**: https://apify.com/fascinating\_lentil/facebook-ad-library-scraper.md
- **Developed by:** [Md Jakaria Mirza](https://apify.com/fascinating_lentil) (community)
- **Categories:** Social media, Other
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 ad scrapeds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

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

## 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 Ad Library Scraper - Competitor Ads, Creatives & Spend

Scrape the public **Facebook Ad Library** in minutes. This Facebook Ad Library scraper extracts ad creatives, copy, headlines, CTAs, spend ranges, impressions, run dates, and targeting info from facebook.com/ads/library for any keyword, advertiser, or Page ID. Export to JSON, CSV, Excel, or HTML, or pull via the Apify API — no login and no API key required, because the Ad Library is a public ad transparency tool.

Built with Node.js 20, TypeScript, and the Apify SDK. It handles pagination, scrolling, and cookie consent automatically, deduplicates by ad ID, and uses Apify residential proxies with retries so runs stay reliable and repeatable.

### What It Extracts

- `adId` — unique Facebook ad identifier
- `advertiserPageName` — name of the advertiser's Facebook page
- `advertiserPageId` — Facebook Page ID
- `advertiserPageUrl` — direct link to the advertiser's page
- `adCreativeText` — primary ad body text
- `adHeadline` — ad headline
- `adDescription` — ad description text
- `ctaButtonText` — call-to-action button text
- `destinationUrl` — link the ad points to
- `adType` — image, video, carousel, or text
- `imageUrl` — primary image URL
- `imageUrls` — all image URLs
- `videoThumbnailUrl` — video thumbnail
- `videoUrl` — direct video URL
- `adStartDate` — when the ad started running
- `adEndDate` — when the ad stopped (if inactive)
- `impressionsRange` — viewership range (e.g. 10K-50K)
- `spendRange` — estimated spend in USD
- `countriesRunningIn` — target countries
- `languages` — ad languages
- `platformsList` — where the ad runs
- `fundingEntity` — funding entity (political ads)
- `paidForByText` — "Paid for by" disclosure
- `targetingInfo` — age, gender, location (if disclosed)
- `adLibraryUrl` — direct link to the ad in the library
- `searchQuery` — original search keyword
- `scrapedAt` — extraction timestamp

### Use Cases

1. **Competitor ad research** — discover which ads competitors are running, their messaging, and creative formats, then benchmark against your own.
2. **Creative intelligence** — analyze high-performing ad copy, headlines, CTAs, and image/video formats across your industry.
3. **Political ad monitoring** — track political advertising spend, funding entities, "Paid for by" disclosures, and targeting across elections.
4. **Spend and impressions benchmarking** — pull spend ranges and impression ranges to estimate competitor budgets and reach.
5. **Brand and trend tracking** — monitor how brands appear in the Ad Library over time and spot new campaigns as they launch.

### Pricing

This Actor uses Apify Pay Per Event pricing. You pay only for ad records successfully saved to the dataset — failed, blocked, or empty results are not billed.

| Event name | Price per event | 1,000 ads | 10,000 ads |
| --- | ---: | ---: | ---: |
| `ad-scraped` | $0.001 | $1.00 | $10.00 |

### Input

| Field | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `keywords` | array | no | `["Nike"]` | Search keywords to find ads. Searched in sequence. |
| `pageIds` | array | no | `[]` | Numeric Facebook Page IDs to scrape ads for directly. |
| `advertiserNames` | array | no | `[]` | Advertiser or Page names to search for. |
| `country` | string | no | `ALL` | ISO 3166-1 alpha-2 code (e.g. US, GB, DE) or ALL. |
| `adCategory` | string | no | `all` | One of all, issues_elections_politics, housing, employment, credit, political. |
| `adStatus` | string | no | `active` | One of active, inactive, all. |
| `platforms` | array | no | all four | facebook, instagram, messenger, audience_network. |
| `maxResults` | integer | no | `20` | Max ads per search query (0 = unlimited, up to 1000). |
| `proxyConfiguration` | object | no | Residential | Apify proxy settings. Residential recommended. |

### Example Input

```json
{
    "keywords": ["Nike"],
    "country": "US",
    "adStatus": "active",
    "maxResults": 50,
    "proxyConfiguration": {
        "useApifyProxy": true,
        "apifyProxyGroups": ["RESIDENTIAL"]
    }
}
````

### How to Scrape the Facebook Ad Library (Step by Step)

1. Click **Try for free** / **Run**.
2. Enter search keywords, advertiser names, or numeric Page IDs.
3. Optionally set a `country`, `adCategory`, `adStatus`, and `platforms` filter.
4. Set `maxResults` (start small, like 20, to test).
5. Run, then export the results as JSON, CSV, Excel, or HTML, or pull them via the Apify API.

### Sample Output

```json
{
    "adId": "1234567890123456789",
    "advertiserPageName": "Nike",
    "advertiserPageId": "150849945690582",
    "advertiserPageUrl": "https://www.facebook.com/profile.php?id=150849945690582",
    "adCreativeText": "Just Do It. New collection available now.",
    "adHeadline": "Shop Now",
    "adDescription": "Explore the latest Nike styles",
    "ctaButtonText": "Shop Now",
    "destinationUrl": "https://www.nike.com/new-releases",
    "adType": "image",
    "imageUrl": "https://scontent.xx.fbcdn.net/v/example.jpg",
    "imageUrls": ["https://scontent.xx.fbcdn.net/v/example.jpg"],
    "videoThumbnailUrl": null,
    "videoUrl": null,
    "adStartDate": "2024-01-15",
    "adEndDate": null,
    "impressionsRange": "10K-50K",
    "spendRange": "$1,000-$5,000",
    "countriesRunningIn": ["US"],
    "languages": ["en"],
    "platformsList": ["facebook", "instagram"],
    "fundingEntity": null,
    "paidForByText": null,
    "targetingInfo": {
        "age": null,
        "gender": null,
        "location": null
    },
    "adLibraryUrl": "https://www.facebook.com/ads/library/?id=1234567890123456789",
    "scrapedAt": "2024-06-10T12:00:00.000Z",
    "searchQuery": "Nike"
}
```

### How It Works

1. Validates the input and builds Ad Library search URLs from your keywords, advertiser names, or Page IDs.
2. Navigates the public Ad Library, handling cookie consent, scrolling, and pagination automatically.
3. Extracts and cleans each ad's fields, falling back to `null` when optional data is not disclosed.
4. Deduplicates results by `adId`.
5. Charges `ad-scraped` only after a clean record is saved, then writes it to the Apify Dataset.

### Known Limits

- Many fields are conditional. `spendRange`, `impressionsRange`, `fundingEntity`, `paidForByText`, and `targetingInfo` are typically populated only for political/issue ads where Meta discloses them; commercial ads often return `null` for these.
- The Ad Library exposes up to roughly 1,000 ads per search, so `maxResults` is capped at 1000.
- Field availability and layout depend on what Meta makes public and can change if the Ad Library changes.

### Ethics & Legal

This Actor scrapes **public data only** from Facebook's Ad Library, a transparency tool Meta provides for public-interest research and ad transparency. No Facebook login or authentication is used and no personal data is collected. You are responsible for complying with Meta's terms, privacy laws, GDPR, and local regulations wherever you use the data.

### License

Apache-2.0. See `LICENSE`.

# Actor input Schema

## `keywords` (type: `array`):

Search keywords to find ads in the Facebook Ad Library. Multiple keywords will be searched in sequence.

## `pageIds` (type: `array`):

Facebook Page IDs to scrape ads for directly. Enter numeric Page IDs.

## `advertiserNames` (type: `array`):

Advertiser or Facebook Page names to search for in the Ad Library.

## `country` (type: `string`):

Filter ads by country. Use ISO 3166-1 alpha-2 code (e.g. US, GB, DE) or ALL for no filter.

## `adCategory` (type: `string`):

Filter by ad category type.

## `adStatus` (type: `string`):

Filter by ad active/inactive status.

## `platforms` (type: `array`):

Filter by platform where the ad is displayed.

## `maxResults` (type: `integer`):

Maximum number of ads to scrape per search query. Set to 0 for unlimited (up to 1000).

## `proxyConfiguration` (type: `object`):

Proxy settings for the crawler. Residential proxies recommended.

## Actor input object example

```json
{
  "keywords": [
    "Nike"
  ],
  "pageIds": [],
  "advertiserNames": [],
  "country": "ALL",
  "adCategory": "all",
  "adStatus": "active",
  "platforms": [
    "facebook",
    "instagram",
    "messenger",
    "audience_network"
  ],
  "maxResults": 20,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  }
}
```

# 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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("fascinating_lentil/facebook-ad-library-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 = {}

# Run the Actor and wait for it to finish
run = client.actor("fascinating_lentil/facebook-ad-library-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 '{}' |
apify call fascinating_lentil/facebook-ad-library-scraper --silent --output-dataset

```

## MCP server setup

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

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Facebook Ad Library Scraper - Competitor Ads & Creatives",
        "description": "Scrape ads from the public Facebook Ad Library. Extract ad creatives, text, headlines, spend ranges, impressions, targeting info, and more.",
        "version": "1.0",
        "x-build-id": "4EaZVwzC20ybCs4gh"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/fascinating_lentil~facebook-ad-library-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-fascinating_lentil-facebook-ad-library-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/fascinating_lentil~facebook-ad-library-scraper/runs": {
            "post": {
                "operationId": "runs-sync-fascinating_lentil-facebook-ad-library-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/fascinating_lentil~facebook-ad-library-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-fascinating_lentil-facebook-ad-library-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",
                "properties": {
                    "keywords": {
                        "title": "Search Keywords",
                        "type": "array",
                        "description": "Search keywords to find ads in the Facebook Ad Library. Multiple keywords will be searched in sequence.",
                        "items": {
                            "type": "string"
                        },
                        "default": [
                            "Nike"
                        ]
                    },
                    "pageIds": {
                        "title": "Page IDs",
                        "type": "array",
                        "description": "Facebook Page IDs to scrape ads for directly. Enter numeric Page IDs.",
                        "items": {
                            "type": "string"
                        },
                        "default": []
                    },
                    "advertiserNames": {
                        "title": "Advertiser / Page Names",
                        "type": "array",
                        "description": "Advertiser or Facebook Page names to search for in the Ad Library.",
                        "items": {
                            "type": "string"
                        },
                        "default": []
                    },
                    "country": {
                        "title": "Country",
                        "type": "string",
                        "description": "Filter ads by country. Use ISO 3166-1 alpha-2 code (e.g. US, GB, DE) or ALL for no filter.",
                        "default": "ALL"
                    },
                    "adCategory": {
                        "title": "Ad Category",
                        "enum": [
                            "all",
                            "issues_elections_politics",
                            "housing",
                            "employment",
                            "credit",
                            "political"
                        ],
                        "type": "string",
                        "description": "Filter by ad category type.",
                        "default": "all"
                    },
                    "adStatus": {
                        "title": "Ad Status",
                        "enum": [
                            "active",
                            "inactive",
                            "all"
                        ],
                        "type": "string",
                        "description": "Filter by ad active/inactive status.",
                        "default": "active"
                    },
                    "platforms": {
                        "title": "Platforms",
                        "type": "array",
                        "description": "Filter by platform where the ad is displayed.",
                        "items": {
                            "type": "string",
                            "enum": [
                                "facebook",
                                "instagram",
                                "messenger",
                                "audience_network"
                            ]
                        },
                        "default": [
                            "facebook",
                            "instagram",
                            "messenger",
                            "audience_network"
                        ]
                    },
                    "maxResults": {
                        "title": "Max Results",
                        "minimum": 0,
                        "maximum": 1000,
                        "type": "integer",
                        "description": "Maximum number of ads to scrape per search query. Set to 0 for unlimited (up to 1000).",
                        "default": 20
                    },
                    "proxyConfiguration": {
                        "title": "Proxy Configuration",
                        "type": "object",
                        "description": "Proxy settings for the crawler. Residential proxies recommended.",
                        "default": {
                            "useApifyProxy": true,
                            "apifyProxyGroups": [
                                "RESIDENTIAL"
                            ]
                        }
                    }
                }
            },
            "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
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
