DEV Community

voiddo
voiddo

Posted on Originally published at voidd0.github.io

Facebook Ad Library scraper: how to get ads as JSON or CSV (Python, API, no code)

Collect public ads from the Meta Ad Library by keyword, advertiser Page ID or Ad Library link: ad text, headline, landing page, button, images and videos, dates, platforms and version count, plus spend and reach ranges where Meta publishes them.

This tutorial shows what the Actor v0iddo/facebook-ads-library-scraper returns, how to run it on the Apify Store without code, and how to call it from Python and cURL.

What data you get

One row per result. Every row can be downloaded as JSON, CSV, Excel or HTML, or read through the API.

Field Label Type Example
adArchiveId Ad ID text 1550534860016399
pageName Advertiser text Perfect themes
isActive Active true/false true
startDate Started date 2026-05-19
endDate Ended date
platforms Platforms list ["facebook", "instagram", "audience_network"]
body Ad text text
title Headline text 𝕊𝕦𝕡𝕖𝕣 𝕙𝕠𝕥 𝕨𝕚𝕕𝕘𝕖𝕥𝕤 𝕒𝕡𝕡 !
ctaText Button text Install now
linkUrl Landing page URL http://play.google.com/store/apps/details?id=com.iconchanger.widget...
displayFormat Format text IMAGE
imageUrls Images list ["https://scontent-lga3-1.xx.fbcdn.net/v/t39.35426-6/700927950_9333...
adLibraryUrl Ad Library link URL https://www.facebook.com/ads/library/?id=1550534860016399
pageId pageId text 115939511520844
pageCategories pageCategories list ["Topic"]
pageLikeCount pageLikeCount number 18620
searchedFor searchedFor text nike
searchCountry searchCountry text US

Real rows from a run of the Actor (fields that name people are left out):

[
  {
    "adArchiveId": "1550534860016399",
    "adLibraryUrl": "https://www.facebook.com/ads/library/?id=1550534860016399",
    "pageId": "115939511520844",
    "pageName": "Perfect themes",
    "pageCategories": [
      "Topic"
    ],
    "pageLikeCount": 18620,
    "isActive": true,
    "startDate": "2026-05-19",
    "platforms": [
      "facebook",
      "instagram",
      "audience_network"
    ],
    "title": "𝕊𝕦𝕡𝕖𝕣 𝕙𝕠𝕥 𝕨𝕚𝕕𝕘𝕖𝕥𝕤 𝕒𝕡𝕡 !",
    "linkUrl": "http://play.google.com/store/apps/details?id=com.iconchanger.widget.theme.shortcut",
    "ctaText": "Install now",
    "displayFormat": "IMAGE",
    "imageUrls": [
      "https://scontent-lga3-1.xx.fbcdn.net/v/t39.35426-6/700927950_933331229664450_6487763311056032772_n.jpg?_nc_cat=111&ccb=1-7&_nc_sid=c53f8f..."
    ],
    "searchedFor": "nike",
    "searchCountry": "US"
  },
  {
    "adArchiveId": "962050096457659",
    "adLibraryUrl": "https://www.facebook.com/ads/library/?id=962050096457659",
    "pageId": "156405867784232",
    "pageName": "Depop",
    "pageCategories": [
      "Shopping"
    ],
    "pageLikeCount": 98483,
    "isActive": true,
    "startDate": "2026-05-22",
    "platforms": [
      "facebook",
      "instagram",
      "messenger"
    ],
    "title": "LOFT Women's Blouse",
    "linkUrl": "http://itunes.apple.com/app/id518684914",
    "linkDescription": "Download Depop - Buy & Sell Clothes by Depop Ltd on the App Store. See screenshots, ratings and reviews, user tips, and more apps like De...",
    "ctaText": "Download",
    "displayFormat": "DPA",
    "imageUrls": [
      "https://scontent-lga3-2.xx.fbcdn.net/v/t39.35426-6/706277483_2044031086227797_898989708800947064_n.jpg?_nc_cat=101&ccb=1-7&_nc_sid=c53f8f...",
      "https://scontent-lga3-3.xx.fbcdn.net/v/t39.35426-6/706317255_2037222576909248_2490268264375552452_n.jpg?_nc_cat=106&ccb=1-7&_nc_sid=c53f8...",
      "https://scontent-lga3-3.xx.fbcdn.net/v/t39.35426-6/706277043_1509973367377594_8218495971134332071_n.jpg?_nc_cat=106&ccb=1-7&_nc_sid=c53f8..."
    ],
    "searchedFor": "nike",
    "searchCountry": "US"
  }
]
Enter fullscreen mode Exit fullscreen mode

No code: run it on the Apify Store

  1. Open the Facebook Ad Library scraper page on Apify.
  2. Fill in the input form. An example input is already filled in.
  3. Press Start, wait for the run to finish, and download the results as JSON, CSV or Excel from the Output tab.

The input that is pre-filled on the Actor page:

{
  "searchTerms": [
    "nike"
  ],
  "country": "US",
  "activeStatus": "active",
  "maxItems": 20
}
Enter fullscreen mode Exit fullscreen mode

Python (apify-client)

Get your API token in Apify Console under Settings, then Integrations. The Actor id is v0iddo/facebook-ads-library-scraper.

from apify_client import ApifyClient

client = ApifyClient("YOUR_APIFY_TOKEN")

run_input = {'searchTerms': ['nike'], 'country': 'US', 'activeStatus': 'active', 'maxItems': 20}

run = client.actor("v0iddo/facebook-ads-library-scraper").call(run_input=run_input)
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)
Enter fullscreen mode Exit fullscreen mode

cURL

curl -X POST "https://api.apify.com/v2/acts/v0iddo~facebook-ads-library-scraper/run-sync-get-dataset-items" \
  -H "Authorization: Bearer YOUR_APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"searchTerms": ["nike"], "country": "US", "activeStatus": "active", "maxItems": 20}'
Enter fullscreen mode Exit fullscreen mode

Good to know

  • If Meta shows a login, verification or CAPTCHA page instead of the Ad Library, the run stops and says so; it never tries to get around that.
  • Not affiliated with Meta. The data is what the public Ad Library shows to a visitor who is not logged in.

Price

$0.50 per 1,000 results. You pay per result row. There is no separate charge per run. Higher Apify plans pay less per result, down to $0.35 per 1,000.

FAQ

What data does the Facebook Ad Library scraper return?

Each result is one row in an Apify dataset. Fields include adArchiveId, pageName, isActive, startDate, endDate, platforms, body, title, and more. The table above shows every field with an example value.

Can I use it without writing code?

Yes. Open the Actor page on Apify, fill in the input form (an example is already filled in), press Start, and download the results as JSON, CSV, Excel or HTML. You can also schedule runs there.

How much does it cost?

$0.50 per 1,000 results. You pay per result row. There is no separate charge per run. Higher Apify plans pay less per result, down to $0.35 per 1,000. A new Apify account gets $5 of platform credit every month.

Links

Top comments (0)