# Facebook Ad Library Scraper (`lentic_clockss/facebook-ad-library-scraper`) Actor

Scrape Facebook Ad Library for ad creatives, spend data, advertiser info, and targeting. Search any keyword, advertiser, or country. No login needed — fully public data.

- **URL**: https://apify.com/lentic\_clockss/facebook-ad-library-scraper.md
- **Developed by:** [kane liu](https://apify.com/lentic_clockss) (community)
- **Categories:** Social media, Marketing, MCP servers
- **Stats:** 2 total users, 2 monthly users, 100.0% runs succeeded, NaN bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

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

## 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

Scrape **Meta (Facebook) Ad Library** for public ad creatives, advertiser pages, copy, images, and video URLs. Search by keyword, country, ad type, and active status. **No Facebook login required** — data comes from Meta’s transparency library.

**Local-first:** Core scraping runs via `src.scraper.scrape_ad_library` (Patchright) on your machine. Publishing to Apify (`apify push`) is **optional** — only when you want a hosted Actor build.

**SEO:** Facebook Ad Library scraper, Facebook ads scraper, Meta Ad Library, ad creative scraper, ad intelligence, competitor ads, Facebook advertising data, ad spy tool, Meta transparency ads.

### Features

- Keyword search across the Ad Library
- Filters: country (ISO code or `ALL`), political vs all ads, active / inactive / all
- Pagination via infinite scroll with GraphQL capture
- First-screen SSR extraction plus live GraphQL responses for additional ads
- Optional **Apify Proxy** for large or sensitive runs
- Structured output: advertiser, body text, titles, CTAs, image URLs, video URLs, archive IDs

### Input

| Field | Type | Description |
|-------|------|-------------|
| `searchQuery` | string | **Required.** Keyword or phrase (e.g. brand name). |
| `country` | string | ISO country code (default `US`) or `ALL`. |
| `adType` | enum | `all` or `political_and_issue_ads`. |
| `activeStatus` | enum | `active`, `inactive`, or `all`. |
| `maxResults` | integer | Cap between 1 and 5000 (default 100). |
| `proxy` | object | Optional Apify proxy configuration. |

### Output (dataset items)

Each record includes (camelCase):

- `adArchiveId`, `collationId`, `pageId`
- `pageName`, `pageProfileUrl`, `pageProfilePictureUrl`
- `bodyText`, `title`, `linkUrl`, `ctaText`, `displayFormat`
- `createdAt` (ISO UTC), `imageUrls`, `videoUrls`
- `collationCount`, `isActive`, `scrapedAt`

### Usage examples

#### Example 1 — Brand monitoring (US, active ads)

```json
{
  "searchQuery": "shopify",
  "country": "US",
  "activeStatus": "active",
  "adType": "all",
  "maxResults": 100
}
````

#### Example 2 — All countries, larger sample

```json
{
  "searchQuery": "crm software",
  "country": "ALL",
  "activeStatus": "active",
  "maxResults": 250
}
```

#### Example 3 — Political ads only

```json
{
  "searchQuery": "climate",
  "country": "GB",
  "adType": "political_and_issue_ads",
  "activeStatus": "all",
  "maxResults": 50
}
```

### Pricing (Apify Store)

Pay-per-event model (example configuration — check the Store for current numbers):

- **Actor start** — small fixed fee per run
- **Per result** — per ad row written to the default dataset

Target positioning: competitive vs official Ad Library actors, with reliable creative fields and stable runs using browser + GraphQL capture.

### Local development

```bash
cd sip-facebook-ad-library-scraper
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
python -m patchright install chromium

## Headful local debug (optional)
export HEADLESS=0
python3 -c "
import asyncio
from src.scraper import scrape_ad_library
async def t():
    ads = await scrape_ad_library('shopify', country='US', max_results=10)
    print(len(ads), ads[0] if ads else None)
asyncio.run(t())
"
```

#### Optional: publish to Apify

Requires [Apify CLI](https://docs.apify.com/cli) and `APIFY_TOKEN` in the environment:

```bash
apify login   ## or export APIFY_TOKEN=...
apify push
```

Skip this if you only need local runs.

### Notes

- Runs use **Patchright** (Chromium). Apify Cloud uses headless Chromium; locally you can set `HEADLESS=0` for debugging.
- Meta may change HTML/GraphQL shapes; prefer reporting failing runs with sample input.
- **Rate & fairness:** scrape only what you need; respect Meta’s terms and applicable laws.

### Legal

This Actor collects **publicly published** information from Meta’s Ad Library (transparency / political & advertising disclosures). You are responsible for compliance with Meta’s terms, API/site policies, and laws in your jurisdiction (copyright, publicity, data protection, election law, etc.). This tool does not bypass authentication for non-public data.

### Support

Issues: use the Apify Actor issue tracker or your workspace support channel.

# Actor input Schema

## `searchQuery` (type: `string`):

Keyword to search for in Facebook Ad Library (e.g. brand name, product, topic).

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

ISO country code to filter ads by reach country. Use 'ALL' for all countries.

## `adType` (type: `string`):

Type of ads to search: 'all' for all ads, 'political\_and\_issue\_ads' for political ads only.

## `activeStatus` (type: `string`):

Filter by ad status: 'active' for currently running ads, 'inactive' for ended ads, 'all' for both.

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

Maximum number of ads to return. Default 100.

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

Proxy configuration. Recommended for large runs.

## Actor input object example

```json
{
  "searchQuery": "shopify",
  "country": "US",
  "adType": "all",
  "activeStatus": "active",
  "maxResults": 100
}
```

# Actor output Schema

## `ads` (type: `string`):

Dataset containing all scraped ad records

# 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 = {
    "searchQuery": "shopify"
};

// Run the Actor and wait for it to finish
const run = await client.actor("lentic_clockss/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 = { "searchQuery": "shopify" }

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

```

## MCP server setup

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

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Facebook Ad Library Scraper",
        "description": "Scrape Facebook Ad Library for ad creatives, spend data, advertiser info, and targeting. Search any keyword, advertiser, or country. No login needed — fully public data.",
        "version": "0.1",
        "x-build-id": "IOiUkQaXzHFX6zITh"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/lentic_clockss~facebook-ad-library-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-lentic_clockss-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/lentic_clockss~facebook-ad-library-scraper/runs": {
            "post": {
                "operationId": "runs-sync-lentic_clockss-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/lentic_clockss~facebook-ad-library-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-lentic_clockss-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",
                "required": [
                    "searchQuery"
                ],
                "properties": {
                    "searchQuery": {
                        "title": "Search Query",
                        "type": "string",
                        "description": "Keyword to search for in Facebook Ad Library (e.g. brand name, product, topic)."
                    },
                    "country": {
                        "title": "Country",
                        "type": "string",
                        "description": "ISO country code to filter ads by reach country. Use 'ALL' for all countries.",
                        "default": "US"
                    },
                    "adType": {
                        "title": "Ad Type",
                        "enum": [
                            "all",
                            "political_and_issue_ads"
                        ],
                        "type": "string",
                        "description": "Type of ads to search: 'all' for all ads, 'political_and_issue_ads' for political ads only.",
                        "default": "all"
                    },
                    "activeStatus": {
                        "title": "Active Status",
                        "enum": [
                            "active",
                            "inactive",
                            "all"
                        ],
                        "type": "string",
                        "description": "Filter by ad status: 'active' for currently running ads, 'inactive' for ended ads, 'all' for both.",
                        "default": "active"
                    },
                    "maxResults": {
                        "title": "Max Results",
                        "minimum": 1,
                        "maximum": 5000,
                        "type": "integer",
                        "description": "Maximum number of ads to return. Default 100.",
                        "default": 100
                    },
                    "proxy": {
                        "title": "Proxy Configuration",
                        "type": "object",
                        "description": "Proxy configuration. Recommended for large runs."
                    }
                }
            },
            "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
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
