How-to

How to Scrape the Facebook Ad Library (2026 Guide)

The Meta Ad Library shows every ad running on Facebook, Instagram, Messenger, Threads and the Audience Network, but only in a browser, one scroll at a time. This guide explains what is actually in the library, why scraping it yourself breaks so often, and how to pull ads, creatives and advertiser data into your own code with a few lines of cURL, Python or JavaScript.

Published 7 min read

What the Facebook Ad Library contains

Meta built the Ad Library (facebook.com/ads/library) as a transparency tool: anyone, logged in or not, can see the ads a page is running right now. For each ad it publishes the advertiser page, the text, the images or videos, the call to action and link, the platforms it runs on and the date it started. Political and issue ads get more: a spend range, an impressions range and the "Paid for by" disclaimer, and they stay in the library for seven years.

Since the EU Digital Services Act came into force, every ad delivered in the European Union also carries transparency data: the estimated number of people it reached in the EU, the age range, gender and locations it targeted, a breakdown of reach by country, age and gender, and who paid for it and who benefits from it. That is the richest public advertising dataset there is, and it covers commercial ads, not only political ones.

What the library does not have is an export button. You can search, filter by country, media type and platform, and scroll. If you want 500 ads of your competitors in a spreadsheet, or a daily alert when a brand launches new creatives, you need to get the data out some other way.

Option 1: copy it by hand

For a one-off look at a single competitor, the browser is fine. Search the brand, choose "All ads" and the country, open the ads that matter and take screenshots. Our free Ad Library search does the same without the infinite scroll and shows each ad with its start date and creatives. The search tips guide explains the filters that save the most time.

Manual research stops working when you need more than a handful of advertisers, when you need the same report every week, or when you want to compute anything (how long ads run, how many variants a brand tests, which hooks repeat). That is when people start writing scrapers.

Option 2: write your own scraper

The library is a single-page app. The first page of results is embedded in the HTML as JSON, the next pages come from GraphQL requests, and the details of one ad (the EU transparency data, the payer) come from yet another query. A scraper that works has to deal with all of the following:

  • An anti-bot challenge. The first request answers with a small JavaScript challenge instead of the page; you have to solve it and keep its cookies before you get any HTML.
  • Rotating query ids. The GraphQL requests use persisted query ids (doc_id) that Meta changes every few weeks. A hard-coded id silently stops returning data.
  • Pagination blocks. Requests for page 2 and beyond from datacenter IPs often answer "Rate limit exceeded", even from a real browser. In practice you need residential proxies to go past the first 30 ads.
  • Expiring media. The image and video URLs point to Meta's CDN and expire after a few days, so a database of links goes stale.
  • A shape that changes. Field names move inside the JSON. Without strict parsing you end up storing half-empty records and noticing weeks later.

None of this is impossible. Browser automation with Playwright or Puppeteer gets you the first page quickly, and open source scrapers exist. The cost is maintenance: someone has to notice when it breaks, re-discover the query ids, buy and rotate proxies, and keep the parser in step with Meta. For a side project that is fun. For a product or a client report that must run every Monday, it is a liability.

Option 3: use an Ad Library API

An Ad Library API does the scraping for you and answers clean, documented JSON. With ScrapeAdLibrary you send an HTTP request with your API key and get up to 30 ads per call, with the same filters as the library itself. There is also Meta's official Ad Library API, but it only covers political ads and ads delivered in the EU, and it requires an identity check: the comparison with the official API goes through the differences in detail.

Step 1: get an API key

Create a free account and copy your key from the dashboard. Keys start with sal_. You get 65 free calls every month with no credit card, and every call costs one credit whatever the number of results, so a search returning 30 ads costs the same as one returning three. After that it is $5 per 1,000 calls (pricing).

Step 2: search ads by keyword

The ads search endpoint takes a keyword (q) or an advertiser page id (page_id), plus the filters of the library: country, status, media_type, platforms, languages, an active_from/active_to window and match=exact for an exact phrase. This request asks for active video ads about running shoes shown in the United States:

curl -s "https://api.scrapeadlibrary.com/v1/ads/search?q=running%20shoes&country=US&media_type=video&limit=10" \
  -H "X-API-Key: $SCRAPEADLIBRARY_API_KEY"

Every response has the same envelope. A shortened example (illustrative values):

{
  "data": [
    {
      "id": "1550534860016399",
      "url": "https://www.facebook.com/ads/library/?id=1550534860016399",
      "page": { "id": "115939511520844", "name": "Example Running Co", "is_person": false,
                "categories": ["Sportswear Store"], "like_count": 18520 },
      "status": "active",
      "started_at": "2026-09-19T07:00:00Z",
      "ended_at": null,
      "platforms": ["facebook", "instagram"],
      "format": "video",
      "body": "Built for your first marathon...",
      "title": "Free shipping this week",
      "link_url": "https://example.com/shoes",
      "cta": { "text": "Shop now", "type": "shop_now" },
      "images": [],
      "videos": [{ "type": "video", "url": "https://video.fbcdn.net/...", "preview_url": "https://scontent.fbcdn.net/...",
                   "sd_url": "https://video.fbcdn.net/...", "expires_at": "2026-12-03T18:00:00Z" }],
      "variants_count": 4,
      "days_active": 71,
      "winning_score": 71
    }
  ],
  "total_estimate": 6780,
  "has_more": true,
  "next_cursor": "c_9Xk2a8ZqLw",
  "credits_used": 1,
  "cached": false,
  "media_expires_at": "2026-12-03T18:00:00Z"
}

Besides the creative itself you get variants_count (how many ads share the same creative, a good sign of how hard an advertiser is testing it) and two derived signals, days_active and winning_score, explained in the winning ads guide.

Step 3: follow the cursor for more pages

One call returns one page of the library, up to 30 ads. When has_more is true, call again with cursor set to next_cursor and the same other parameters (changing a filter with an old cursor answers 400 cursor_mismatch). Cursors live for one hour. This loop collects up to 150 ads, five calls:

import os
import requests

API = "https://api.scrapeadlibrary.com"
HEADERS = {"X-API-Key": os.environ["SCRAPEADLIBRARY_API_KEY"]}
params = {"q": "running shoes", "country": "US", "status": "active"}

ads, cursor = [], None
for _ in range(5):  # 5 pages = 5 credits
    page_params = {**params, "cursor": cursor} if cursor else params
    page = requests.get(API + "/v1/ads/search", params=page_params, headers=HEADERS, timeout=60).json()
    ads.extend(page["data"])
    if not page["has_more"]:
        break
    cursor = page["next_cursor"]

print(len(ads), "ads")

Step 4: go from one ad to the advertiser

Three more endpoints complete the picture. GET /v1/ads/{ad_id} returns one ad in full: the advertiser page, payer and beneficiary, and the EU and UK transparency data. GET /v1/pages/{page_id}/ads lists every ad of one advertiser, and GET /v1/pages/search?q= finds advertisers that ran ads on a keyword, with their page id. Each is one credit per call.

# Every active ad of one advertiser page, most impressions first
curl -s "https://api.scrapeadlibrary.com/v1/pages/15087023444/ads?country=US&sort=impressions" \
  -H "X-API-Key: $SCRAPEADLIBRARY_API_KEY"

# The full detail of one ad, with EU reach by country, age and gender
curl -s "https://api.scrapeadlibrary.com/v1/ads/1550534860016399" -H "X-API-Key: $SCRAPEADLIBRARY_API_KEY"

Doing it reliably

A few habits make a scraping job that runs unattended for months:

  1. Branch on the error code, not the message. Errors come back as {"error": "...", "message": "..."} at the top level. Retry 429 rate_limit_exceeded after the Retry-After header and 503 upstream_unavailable or 504 upstream_timeout after a short pause; fix your request on 400 invalid_parameter. The error reference lists them all.
  2. Download media you want to keep. Image and video URLs expire after a few days (expires_at on each file, media_expires_at on the response). Save the files the same day: the creatives guide has a script.
  3. Store the ad id. The id is the Ad Library id and never changes, so it is the natural key for deduplication and for following an ad over time.
  4. Watch your balance. The X-Credits-Remaining header tells you what is left after each call. Errors are never billed.
ApproachSetupMaintenancePaginationEU transparency data
Copy by handNoneNoneScrollingOne ad at a time
Own scraperDaysOngoing (query ids, proxies, parser)Needs residential proxiesExtra GraphQL query
Official Meta APIIdentity check, app reviewLowYesEU and political ads only
Ad Library APIMinutesNoneCursorOne call per ad

Where to go from here

Once the data flows, the interesting part begins: watching what competitors launch, tracking how long their ads run, or building a weekly report for clients (ad research for agencies). And if you plan to use the data commercially, read the legal side of scraping the Ad Library first.

Frequently asked questions

Can I scrape the Facebook Ad Library without logging in?
Yes. The Ad Library is public and works logged out, which is also how the API reads it: no Facebook account, no login and no captcha solving. You only need an API key for the API itself.
How many ads can I get per request?
Up to 30 ads per call, one page of the library. For more, follow next_cursor: each further page is one more call and one more credit.
Does it work for Instagram ads?
Yes. The Ad Library covers Facebook, Instagram, Messenger, Threads and the Audience Network, and every ad lists its platforms. Filter with platforms=instagram to keep only ads that run on Instagram.
Do I need proxies?
Not with the API: it handles sessions, proxies and retries on its side. If you write your own scraper, expect to need residential proxies to paginate past the first page of results.
What does it cost?
65 calls a month are free, then $5 per 1,000 calls with no subscription. Every successful call costs one credit whatever the number of ads it returns, and errors cost nothing.

Related guides

← All guides

Try it on your own competitors

Create a free account and get 65 free calls every month, no credit card. One API key works on every endpoint.