Call the Facebook Ad Library Scraper from Python with the official apify-client.
pip install apify-clientfrom apify_client import ApifyClient
client = ApifyClient("YOUR_TOKEN")
run = client.actor("logiover/meta-ad-library-scraper").call(run_input={
"searchTerms": ["nike", "running shoes"],
"country": "US",
"activeStatus": "active",
"maxResults": 500,
})
for ad in client.dataset(run["defaultDatasetId"]).iterate_items():
print(ad["pageName"], "—", ad["status"], "—", ad["adLibraryUrl"])run = client.actor("logiover/meta-ad-library-scraper").call(run_input={
"pageIds": ["15087023444"],
"country": "US",
"activeStatus": "all",
"maxResults": 1000,
})
items = list(client.dataset(run["defaultDatasetId"]).iterate_items())
print(f"Collected {len(items)} ads")import pandas as pd
rows = list(client.dataset(run["defaultDatasetId"]).iterate_items())
df = pd.DataFrame(rows)
swipe = df[["pageName", "bodyText", "ctaText", "linkUrl", "publisherPlatform", "startDate"]]
swipe.to_csv("facebook_ads_swipe.csv", index=False)
print(swipe.head(20))run = client.actor("logiover/meta-ad-library-scraper").call(run_input={
"searchTerms": ["election"],
"country": "US",
"adType": "political_and_issue_ads",
"maxResults": 500,
})
for ad in client.dataset(run["defaultDatasetId"]).iterate_items():
if ad.get("spendLowerBound") is not None:
print(
ad["pageName"],
f'{ad["spendLowerBound"]}-{ad["spendUpperBound"]} {ad.get("currency")}',
ad.get("impressions"),
)The client resolves your token, runs the hosted Actor on Apify, and returns structured results. Nothing is scraped locally.