Facebook Ad Library Scraper: Complete Guide + Working Code (2026)
What a Facebook Ad Library scraper does, working Playwright code, proxies, schema, legality, and when to buy vs build. The definitive 2026 reference.
A Facebook Ad Library scraper is the bridge between the browser-only Facebook Ad Library and structured, queryable data. If you have ever copy-pasted ads into a spreadsheet, screenshotted them by hand, or wished you could search the Facebook Ad Library across brands at once, you need a Facebook Ad Library scraper. This guide walks through what a Facebook Ad Library scraper is, the four ways to get one, the legal and technical fundamentals, and a working code example you can run today.
What is a Facebook Ad Library scraper?
A Facebook Ad Library scraper is a program that automates the Facebook Ad Library at facebook.com/ads/library and returns ad data — creatives, copy, page name, start date, landing URL, platforms — as JSON, CSV, or rows in a database. The Facebook Ad Library UI does not allow exports, so a Facebook Ad Library scraper is the standard workaround.
Why you need a Facebook Ad Library scraper
- The Facebook Ad Library has no "export" button. A Facebook Ad Library scraper is the export.
- The Facebook Ad Library hides ads the moment they stop running. A Facebook Ad Library scraper snapshots them so you keep history.
- The Facebook Ad Library does not support cross-brand search. A Facebook Ad Library scraper into a database does.
- The Facebook Ad Library has no API for commercial ads. A Facebook Ad Library scraper is the only route.
How a Facebook Ad Library scraper works
The Facebook Ad Library is a JavaScript-rendered application. A Facebook Ad Library scraper has to either drive a real browser (Playwright/Puppeteer) or replicate the GraphQL calls the Library makes internally. Either way the steps are:
- Build the Facebook Ad Library URL with search parameters.
- Render the page (or call the internal endpoint).
- Wait for the first ad result to appear.
- Scroll or paginate through the cursor.
- Parse each ad node into structured fields.
- Download media references and persist everything.
Working Facebook Ad Library scraper example
Below is a minimal Facebook Ad Library scraper in Python with Playwright. It will hit the Facebook Ad Library for a single brand and country and return the rendered ad results.
# fb_ad_library_scraper.py
import asyncio, json
from playwright.async_api import async_playwright
async def scrape_facebook_ad_library(brand: str, country: str = "US"):
url = (
"https://www.facebook.com/ads/library/?"
f"active_status=active&ad_type=all&country={country}&q={brand}"
)
async with async_playwright() as p:
browser = await p.chromium.launch(headless=True)
page = await browser.new_page()
await page.goto(url)
try:
await page.wait_for_selector(
"[data-testid='ad-library-result']", timeout=10000)
except Exception:
return []
# Scroll a few times to trigger pagination in the Facebook Ad Library
for _ in range(5):
await page.mouse.wheel(0, 4000)
await page.wait_for_timeout(1500)
ads = await page.eval_on_selector_all(
"[data-testid='ad-library-result']",
"els => els.map(e => ({ text: e.innerText }))"
)
await browser.close()
return ads
if __name__ == "__main__":
print(json.dumps(asyncio.run(
scrape_facebook_ad_library("Nike", "US")
), indent=2))
This Facebook Ad Library scraper works for hobby projects. It does not work for production: no proxy rotation, no fingerprinting, no media download, no error handling, no schema. Building the production version is what the next section is about.
Building a production Facebook Ad Library scraper
To take a Facebook Ad Library scraper from hobby to production you need:
- Residential proxies (Bright Data, Oxylabs, Smartproxy). The Facebook Ad Library throttles repeated requests from the same IP.
- Browser fingerprint pooling — User-Agent, canvas, WebGL, screen size.
- A queue + worker model — RabbitMQ or SQS, with retry + backoff.
- Media pipeline — download every image/video the Facebook Ad Library serves, store in S3, mint cloaked URLs.
- Structured storage — Postgres for metadata, a search index for keyword queries.
- Schema versioning — Meta changes the Facebook Ad Library DOM regularly; your scraper needs versioned parsers.
| Stage | Tool we use | Why |
|---|---|---|
| Render | Playwright + Chromium | Reliable across Library UI changes |
| Proxies | Residential rotating | Avoid Facebook Ad Library throttling |
| Queue | Redis + RQ | Cheap + fast |
| Metadata DB | Postgres | Full-text + cursor pagination |
| Search | Meilisearch | ms latency over millions of ads |
| Media | S3 + Cloudflare | Cheap + cacheable |
Buy a Facebook Ad Library scraper, or build one?
Building a Facebook Ad Library scraper takes 2–3 weeks for v1 and 1 week per quarter to maintain as Meta changes the Library. Proxies cost $200–$600/month. If your only objective is to use the data, a managed Facebook Ad Library scraper like AdScrape is dramatically cheaper than building one in-house.
Build if:
- The data must live entirely on your infrastructure.
- You need a fully bespoke schema or scraping cadence.
- You are an engineer who enjoys it.
Buy if:
- You want a Facebook Ad Library scraper as a feature, not a product.
- You want an API + dashboard out of the box.
- You care about uptime more than custom logic.
Is a Facebook Ad Library scraper legal?
Reading the Facebook Ad Library is explicitly invited by Meta. Scraping public web data is broadly legal in the US, EU, UK and India, with caveats. We unpack the nuances in Is scraping Facebook ads legal?. The safe defaults: don't scrape user comments, don't republish creatives, respect deletion requests.
Facebook Ad Library scraper vs official APIs
| Approach | Returns commercial ads? | Effort |
|---|---|---|
| Official Meta Ad API (Graph) | No — political only | Low |
| DIY Facebook Ad Library scraper | Yes | High |
| Managed Facebook Ad Library scraper | Yes | Low |
A Facebook Ad Library scraper is required because Meta's official API does not cover commercial ads — see our Meta Ad API guide for the full breakdown.
Facebook Ad Library scraper FAQ
What is the best Facebook Ad Library scraper?
For an API + dashboard, AdScrape. For dropshipping, Minea. For enterprise mobile gaming, SocialPeta. For free, the Meta Ad Library + manual workflows.
Can a Facebook Ad Library scraper bypass logins?
No — and a good Facebook Ad Library scraper doesn't need to. The Facebook Ad Library is public.
How often should a Facebook Ad Library scraper refresh?
Daily is enough for almost every use case. For launch detection, every 6 hours. Anything more frequent gets you throttled without value.
Does a Facebook Ad Library scraper need an API key?
A DIY Facebook Ad Library scraper needs no key — the Library is public. A managed Facebook Ad Library scraper needs an API key from the provider (free tiers available).
Can a Facebook Ad Library scraper pull Instagram ads?
Yes. Instagram ads run through Meta Ads and appear in the Facebook Ad Library, so any Facebook Ad Library scraper that reads the Library covers Instagram too.
Put this into practice with AdScrape
Search every active Meta ad, compare brands side-by-side, and pull it all through a clean REST API. Free to start, no credit card required.