Facebook Ad Library Scraper: Pull Competitor Ads at Scale
The Facebook Ad Library is the best free gift Meta ever gave marketers: every active ad, from every advertiser, visible to anyone. The catch is it's built for browsing one ad at a time. There's no "export all," no "show me ads running longer than 30 days" (the single best signal of a profitable ad), no way to diff a competitor's creatives week over week. For an agency or a serious media buyer, clicking through ads by hand doesn't scale.
This guide automates it with SociaVault: resolve a competitor's page, pull their active ads, and flag the likely winners. Code in JavaScript.
Step 1: Resolve the advertiser
You can't query by brand name directly — you need the page. The search-companies endpoint resolves a name to advertiser pages.
const API_KEY = process.env.SOCIAVAULT_API_KEY;
const BASE = "https://api.sociavault.com/v1/scrape/facebook-ad-library";
async function findPage(brand) {
const res = await fetch(
`${BASE}/search-companies?query=${encodeURIComponent(brand)}`,
{
headers: { "x-api-key": API_KEY },
},
);
const json = await res.json();
if (!json.success) throw new Error(json.error);
const matches = json.data; // log to confirm shape; pick the right page
console.log(matches);
return matches?.[0]?.id;
}
Eyeball the results and pick the right page — big brands often have regional or look-alike entries.
Step 2: Pull their active ads
The company-ads endpoint takes a pageId plus filters: status (ACTIVE/INACTIVE/ALL), country, media_type (IMAGE/VIDEO/...), and a cursor.
async function getAds(pageId, { country = "US", media_type = "VIDEO" } = {}) {
const params = new URLSearchParams({
pageId,
status: "ACTIVE",
country,
media_type,
trim: "true",
});
const res = await fetch(`${BASE}/company-ads?${params}`, {
headers: { "x-api-key": API_KEY },
});
const json = await res.json();
if (!json.success) throw new Error(json.error);
// Log json.data once to confirm ad field names (headline, start date, media url).
return json.data.ads || json.data.results || json.data || [];
}
Step 3: Find the winners
Here's the insight that turns raw ads into intelligence: an ad that's been running a long time is almost certainly profitable. Nobody keeps paying to run a losing ad for a month. So filter by how long each ad has been active.
function findWinners(ads, minDays = 30) {
const cutoff = Date.now() - minDays * 86400000;
return ads.filter((ad) => {
const start = new Date(ad.startDate || ad.start_date || ad.startedRunning);
return !isNaN(start) && start.getTime() < cutoff;
});
}
const pageId = await findPage("Monday.com");
const ads = await getAds(pageId);
const winners = findWinners(ads);
console.log(
`${winners.length} of ${ads.length} ads have run 30+ days (likely profitable)`,
);
I read the start-date field defensively because the exact key can vary — log one ad and lock it in. The 30-day rule is a heuristic, not certainty (a brand could be running a long campaign for brand reasons), but for direct-response advertisers it's a remarkably reliable "this is working" tell.
What to do with it
Run this every morning against your top competitors and you've got a competitive dashboard:
- Creative teams get a fresh folder of competitor video ads as a swipe file.
- Media buyers see which headlines and angles rivals are testing right now — and which ones survived past 30 days.
- Agencies walk into client calls with real competitive intelligence instead of vibes.
Facebook creatives churn fast — a brand might ship 50 new variations a week — which is exactly why manual checking fails and automation wins. The same approach works for LinkedIn ads, just at lower volume.
Frequently Asked Questions
Can you bulk-export ads from the Facebook Ad Library?
Not through the Ad Library UI — it's built for browsing one ad at a time with no export or duration filter. A scraping API lets you pull a competitor's full active ad set programmatically and filter it however you want, which is the whole point of automating it.
How do I find a competitor's page to scrape ads from?
Resolve the brand name to an advertiser page using a search-companies endpoint, then use that page's ID to pull its ads. You can't query the ad library by brand name directly, so this resolve step comes first.
How can I tell which competitor ads are working?
Filter by how long each ad has been running. Direct-response advertisers don't keep paying for losing ads, so an ad active for 30+ days is very likely profitable. It's a heuristic, not a guarantee, but it reliably surfaces a competitor's proven creatives.
Can I download the ad videos and images?
Yes — the ad data includes media URLs you can save into a swipe file. Filter to the media type you want (e.g. VIDEO) and pull the creative URLs from each ad. Confirm the exact field name against a real response.
Is scraping the Facebook Ad Library legal?
The Ad Library is a public transparency tool Meta built specifically to make ads visible to everyone, so reading it is standard competitive research. Stay on public data, respect rate limits, and use the creatives for inspiration and analysis rather than copying them outright.
How often should I scrape competitor ads?
Daily or every few days for active advertisers, since Facebook creatives turn over quickly. A daily pull lets you catch new tests as they launch and watch which ones survive past the 30-day mark.
The bottom line
The Ad Library is a goldmine the UI makes painful to mine. Resolve the page, pull the active ads, and filter for the long-runners — and you've got a live feed of your competitors' proven creatives and current tests, updated every morning.
Want to build your ad-spy tool? Start free with SociaVault with 50 credits.
Found this helpful?
Share it with others who might benefit
Ready to Try SociaVault?
Start extracting social media data with our powerful API. No credit card required.