# Facebook Ad Library Scraper (Playwright) (`admo-solutions/fb-ad-library-scraper`) Actor

Scrape ads from Meta Ad Library using Playwright. Intercepts GraphQL responses for structured data extraction. No API key or Facebook account required.

- **URL**: https://apify.com/admo-solutions/fb-ad-library-scraper.md
- **Developed by:** [Admo Solutions](https://apify.com/admo-solutions) (community)
- **Categories:**
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $10.00 / 1,000 results

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

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

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — 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 ads from Meta's public Ad Library using Playwright. Supports two modes: **keyword search** and **Facebook page scraping**. Extracts comprehensive ad data including page IDs, URLs, CTA details, platforms, and carousel cards — no API key or Facebook account required.

### Why use this Actor?

- **Two scraping modes** — Search by keyword OR scrape ads from Facebook page URLs
- **No API key required** — Uses the public Ad Library website
- **Relay cache extraction** — Parses embedded GraphQL data from page source for complete field coverage
- **Residential proxy support** — Built-in proxy rotation for reliable scraping
- **Deduplication** — Automatically deduplicates by ad archive ID
- **Structured output** — Clean JSON dataset with full ad metadata
- **Self-contained** — No external Actor dependencies

### How to use

#### Mode 1: Search by keyword

1. Enter a search term (e.g., "skincare", "fitness coaching", "SaaS")
2. Optionally set a country code (e.g., "US", "IN", "GB")
3. Run the Actor

#### Mode 2: Scrape ads from Facebook pages

1. Add Facebook page URLs to the "Facebook Page URLs" field
2. Optionally set a country code
3. Run the Actor

Supported URL formats:

- `https://www.facebook.com/ZapierApp`
- `https://www.facebook.com/profile.php?id=123456`
- `facebook.com/YourPage`

### Input

| Field | Description | Default |
|-------|-------------|---------|
| Search Terms | Keywords to search in Ad Library (search mode) | "skincare" |
| Page URLs | Facebook page URLs to scrape ads from (page mode) | \[] |
| Country Code | ISO 2-letter country code | "US" |
| Ad Type | Filter by ad category | "ALL" |
| Active Status | Filter by active/inactive | "ACTIVE" |
| Max Items | Maximum ads to extract | 100 |
| Max Scrolls | Scroll iterations | 20 |
| Scroll Delay | Delay between scrolls (ms) | 2000 |

### Output

Each ad contains:

| Field | Description | Source |
|-------|-------------|--------|
| `adArchiveId` | Unique ad identifier | Relay cache |
| `pageId` | Facebook page ID | Relay cache |
| `pageName` | Advertiser page name | Relay cache |
| `pageUrl` | Advertiser Facebook page URL | Relay cache |
| `body` | Ad text content | Relay cache |
| `title` | Ad headline | Relay cache |
| `linkUrl` | CTA destination URL | Relay cache |
| `ctaText` | CTA button text (e.g., "Learn more") | Relay cache |
| `ctaType` | CTA type (e.g., "LEARN\_MORE", "SHOP\_NOW") | Relay cache |
| `startDate` | When the ad started running (Unix timestamp) | Relay cache |
| `isActive` | Whether the ad is currently active | Relay cache |
| `platforms` | Where the ad runs (Facebook, Instagram, etc.) | Relay cache |
| `mediaType` | Ad format (image, video, carousel, text) | Relay cache |
| `snapshot` | Additional metadata (categories, likes, cards) | Relay cache |

#### Output Example

```json
{
    "adArchiveId": "1591671712123479",
    "pageId": "108268605296897",
    "pageName": "TikTok - US",
    "pageUrl": "https://www.facebook.com/100083860366075/",
    "body": "Fun awaits, no delays.",
    "title": "{{product.name}}",
    "linkUrl": "http://play.google.com/store/apps/details?id=com.zhiliaoapp.musically",
    "ctaText": "Learn more",
    "ctaType": "LEARN_MORE",
    "startDate": 1774508400,
    "isActive": true,
    "platforms": ["FACEBOOK", "INSTAGRAM", "AUDIENCE_NETWORK", "MESSENGER", "THREADS"],
    "mediaType": "carousel",
    "snapshot": {
        "pageCategories": ["Entertainment website"],
        "pageLikeCount": 157244,
        "cards": [{"title": "Treat yourself on TikTok.", "linkUrl": "https://www.tiktok.com/"}]
    }
}
```

### How it works

This Actor uses Playwright to load the Meta Ad Library page, then extracts ad data from the embedded Relay cache (serialized GraphQL data in the page source):

1. **Navigation** — Loads the Ad Library search results page
2. **Relay cache extraction** — Parses the embedded `ad_library_main.search_results_connection.edges` JSON from the page source
3. **Scrolling** — Scrolls to load more ads and re-extracts from updated page source
4. **DOM fallback** — If Relay cache extraction fails, falls back to DOM-based text parsing
5. **Deduplication** — Deduplicates by ad archive ID

### Tips

- Use residential proxy for best results (Facebook blocks datacenter IPs)
- Higher scroll count = more results but longer runtime
- Start with 100 items to test, then increase as needed
- Deduplication happens automatically by ad archive ID

### Cost Estimation

This Actor runs Playwright browser automation. Typical costs:

- 100 ads: ~$0.05-0.15 compute
- 1000 ads: ~$0.50-1.50 compute
- Proxy costs depend on your plan

### Known Limitations

- **Facebook may block requests** without residential proxy
- **Ad Library page structure changes** may require updates to the Relay cache parser
- **Image/video URLs** may be empty for some ad formats (carousel cards often lack direct image URLs in the cache)

### Disclaimer

> Our Actors are ethical and do not extract any private user data. They only extract what has been chosen to share publicly on the Meta Ad Library. We therefore believe that our Actors, when used for ethical purposes by Apify users, are safe. However, you should be aware that your results could contain personal data. Personal data is protected by the GDPR in the European Union and by other regulations around the world. You should not scrape personal data unless you have a legitimate reason to do so. If you're unsure whether your reason is legitimate, consult your lawyers.

### Support

- Having trouble? Open an **Issue** on the Actor page.
- For programmatic access, see the **API** tab.

# Actor input Schema

## `searchTerms` (type: `string`):

Keywords to search in Facebook Ad Library (e.g., 'skincare', 'fitness coaching', 'SaaS'). Used in search mode.

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

ISO 2-letter country code to filter ads (e.g., 'US', 'IN', 'GB', 'DE'). Leave empty for worldwide.

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

Filter by ad category.

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

Filter by ad active status.

## `maxItems` (type: `integer`):

Maximum number of ads to extract. Higher values take longer.

## `maxScrolls` (type: `integer`):

Maximum number of scroll iterations. More scrolls = more results loaded.

## `scrollDelay` (type: `integer`):

Delay between scroll operations in milliseconds. Lower = faster but riskier.

## `pageUrls` (type: `array`):

List of Facebook page URLs to scrape ads from (e.g., 'https://www.facebook.com/ZapierApp'). When provided, scrapes ads from these pages instead of keyword search.

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

Proxy settings. Residential proxy strongly recommended for Facebook scraping.

## Actor input object example

```json
{
  "searchTerms": "skincare",
  "country": "US",
  "adType": "ALL",
  "activeStatus": "ACTIVE",
  "maxItems": 100,
  "maxScrolls": 20,
  "scrollDelay": 2000,
  "pageUrls": [],
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}
```

# Actor output Schema

## `dataset` (type: `string`):

No description

# 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 = {
    "searchTerms": "skincare",
    "country": "US",
    "adType": "ALL",
    "activeStatus": "ACTIVE",
    "maxItems": 100,
    "maxScrolls": 20,
    "scrollDelay": 2000,
    "pageUrls": []
};

// Run the Actor and wait for it to finish
const run = await client.actor("admo-solutions/fb-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 = {
    "searchTerms": "skincare",
    "country": "US",
    "adType": "ALL",
    "activeStatus": "ACTIVE",
    "maxItems": 100,
    "maxScrolls": 20,
    "scrollDelay": 2000,
    "pageUrls": [],
}

# Run the Actor and wait for it to finish
run = client.actor("admo-solutions/fb-ad-library-scraper").call(run_input=run_input)

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

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

```

## CLI example

```bash
echo '{
  "searchTerms": "skincare",
  "country": "US",
  "adType": "ALL",
  "activeStatus": "ACTIVE",
  "maxItems": 100,
  "maxScrolls": 20,
  "scrollDelay": 2000,
  "pageUrls": []
}' |
apify call admo-solutions/fb-ad-library-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,admo-solutions/fb-ad-library-scraper"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/Gh5outvTX2bNT8MfG/builds/svVwwCV4rECuevUlX/openapi.json
