# Facebook Ads Library Scraper (`moving_beacon-owner1/my-actor-28`) Actor

A Python tool to extract ad data from the Facebook Ads Library for research, analysis, or competitive insights.

- **URL**: https://apify.com/moving_beacon-owner1/my-actor-28.md
- **Developed by:** [Jamshaid Arif](https://apify.com/moving_beacon-owner1) (community)
- **Categories:** Developer tools, Social media, SEO tools
- **Features:** Limited permissions
- **Stats:** 79 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?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
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.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

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

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Facebook Ads Library Scraper

A Python-based tool to scrape public ads from the **Facebook Ads Library**, including advertiser names, ad links, and descriptions. Designed for research, competitive analysis, and ad intelligence.

***

### Features

- Extracts advertiser names, ad links, and ad descriptions
- Handles multiple ads per advertiser
- Outputs structured data ready for CSV or JSON
- Supports dynamic content loading via browser automation

***

### Data Structure

Each scraped ad contains:

- **Name**: Advertiser or brand name
- **Link**: URL of the ad or landing page
- **Description**: Text or creative of the ad

***

### Usage

- Set your search parameters such as keywords, advertiser, or location
- Run the scraper to collect ads
- Export results to CSV or JSON if needed

***

### Example Output

| Name    | Link                                                   | Description          |
| ------- | ------------------------------------------------------ | -------------------- |
| Brand A | <https://brand.com/landing> | Buy now and save 30% |
| Brand B | <https://shop.example.com>   | Limited time offer   |

***

### Notes

- Only public ads are accessible
- Scraping large volumes may trigger CAPTCHA or temporary blocks
- Use visible browser mode for best results
- Respect Facebook’s Terms of Service and local laws

***

### Use Cases

- Ad creative research
- Competitor ad monitoring
- Market trend analysis
- Marketing intelligence dashboards

***

### Limitations

- Cannot access private or unpublished ads
- Facebook UI changes may require updates to the scraper
- Heavy usage may require proxies to avoid blocks

***

# Actor input Schema

## `query` (type: `string`):

Keywords to search Facebook Ads Library for.

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

ISO country code (US, GB, DE, IN, etc.) for the ads library region.

## `targetAds` (type: `integer`):

Stop after collecting this many unique ads.

## `idleTimeoutSec` (type: `integer`):

Stop if no new ads appear for this many seconds. Feed exhaustion or soft block.

## `maxRuntimeSec` (type: `integer`):

Hard ceiling on total scrape time.

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

Proxy configuration. Apify Residential strongly recommended — Facebook blocks datacenter IPs aggressively on the Ads Library endpoint.

## `maxSessionRetries` (type: `integer`):

How many times to rotate to a fresh proxy session and relaunch the browser after a block or stall. 0 disables rotation.

## `firstResultsTimeoutSec` (type: `integer`):

How long to wait for the first ads after the page loads before the session is classified as blocked or empty.

## `blockErrorThreshold` (type: `integer`):

Number of consecutive failed GraphQL responses (HTTP error, HTML, Facebook error envelope, failed request) that counts as a block.

## `scrollDelayMs` (type: `integer`):

Pause between scroll steps; a random 0-800 ms jitter is added on top.

## `blockMedia` (type: `boolean`):

Abort image, video and font requests to cut proxy bandwidth. Ad data comes from GraphQL, so nothing is lost.

## Actor input object example

```json
{
  "query": "nike",
  "country": "US",
  "targetAds": 50,
  "idleTimeoutSec": 25,
  "maxRuntimeSec": 900,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  },
  "maxSessionRetries": 4,
  "firstResultsTimeoutSec": 45,
  "blockErrorThreshold": 2,
  "scrollDelayMs": 2000,
  "blockMedia": true
}
```

# 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 = {
    "proxyConfiguration": {
        "useApifyProxy": true,
        "apifyProxyGroups": [
            "RESIDENTIAL"
        ]
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("moving_beacon-owner1/my-actor-28").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 = { "proxyConfiguration": {
        "useApifyProxy": True,
        "apifyProxyGroups": ["RESIDENTIAL"],
    } }

# Run the Actor and wait for it to finish
run = client.actor("moving_beacon-owner1/my-actor-28").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 '{
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  }
}' |
apify call moving_beacon-owner1/my-actor-28 --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,moving_beacon-owner1/my-actor-28"
        }
    }
}
```

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/3NylVhZOt1dYXatZZ/builds/nIuyZWIrRNbrJjew4/openapi.json
