Scrape the posts from a Facebook page to JSON, newest first, with engagement counts and media. Built on the Scrapier API: one HTTPS request, no headless browser to run, no parser to maintain.
Quickstart · Fields · CLI · FAQ
-
Get an API key from the Scrapier dashboard. No credit card needed to start.
-
Install:
pip install git+https://github.com/get-scrapier/Facebook-Page-Posts-Scraper
-
Run:
from scrapier_facebook_page_posts import FacebookPagePosts
client = FacebookPagePosts(api_key="sk_live_...") # or set SCRAPIER_API_KEY
for post in client.iter_page_posts("nytimes", max_items=50):
print(post["timestamp"], post["reactions_count"], post["message"])The same code is in examples/quickstart.py.
- Competitor monitoring
- Engagement analysis
- News tracking
- Social reporting
Walks a Facebook page's posts, newest first, with the engagement counts
and any attached media on each row. Date-windowed with newer_than
and older_than.
A page or profile can be given as a full URL or as the bare vanity name
-- "mrbeast" works as well as https://www.facebook.com/mrbeast.
Wraps the Scrapier facebook-page-posts endpoint.
# 1. A list. For scripts and one-liners.
rows = client.page_posts(target, max_items=100)
# 2. A generator. Streams, so you can stop early and stop paying.
for row in client.iter_page_posts(target):
handle(row)
# 3. A page at a time. You hold the cursor, so you can resume later.
page = client.page_posts_page(target)
save(page.items)
while page.has_more:
page = client.page_posts_page(cursor=page.next_cursor)
save(page.items)A Page carries the rows plus the envelope:
page.items # the rows
page.next_cursor # opaque string, or None
page.has_more # bool
page.raw_responses # upstream payloads, when raw_data=True
page.data # the whole envelope
len(page) # number of rowsObserved on live responses, not copied from a schema.
| Field | Notes |
|---|---|
message |
the post text. Not text -- that is the group-posts endpoint |
post_id, url, timestamp |
identity and time |
reactions_count, comments_count, reshare_count |
engagement |
reactions |
the per-type breakdown, when present |
type |
post kind |
image, video, video_files, video_thumbnail |
media |
album_preview, attached_event, attached_post, attached_post_url |
attachments |
author, external_url |
who posted, and any outbound link |
| Argument | What it does |
|---|---|
newer_than |
Only posts after this date. |
older_than |
Only posts before this date. Pair the two to window a range. |
cookie_string |
Your own Facebook session, which lets the scrape see what your account can see. A credential: keep it out of source control and treat a leak as you would a leaked password. What you collect with it is still subject to Facebook's terms and to privacy law. |
The post text is in message. The group-posts endpoint calls the
same thing text, and the single-post endpoint also uses text.
This is the easiest thing to get wrong when moving between the Facebook
packages.
Rows give a total reactions_count rather than a per-type breakdown.
For all seven reaction types separately you need the single-post
endpoint, scrapier-facebook-post.
Each page is a billable request, so bound a broad walk:
client.page_posts(target, max_items=200) # stop after 200 rows
client.page_posts(target, max_pages=5) # stop after 5 requestsmax_items truncates mid-page rather than buying another page to fill a
quota. Checking your balance is free:
print(client.credits())
print(client.account())AsyncFacebookPagePosts exposes every method FacebookPagePosts does,
with identical arguments.
import asyncio
from scrapier_facebook_page_posts import AsyncFacebookPagePosts
async def main():
async with AsyncFacebookPagePosts() as client:
rows = await client.page_posts(target)
asyncio.run(main())For hundreds of inputs, submit one background job instead of paging:
job = client.bulk([...], max_items=1000) # up to 10,000 per input
print(job.job_id, job.status)
rows = job.wait(timeout=1800, poll_interval=5)Reattach from another process with client.job(job_id), then read
job.data.
Submits are deduplicated server-side on the request parameters, so an identical submit returns the job the first one created — including when that job failed. Vary a parameter to force a fresh attempt.
Everything derives from ScrapierError, so one except can catch the
lot while you still get to be specific when it matters.
from scrapier_facebook_page_posts import InsufficientCreditsError, RateLimitError, ScrapierError
try:
rows = client.page_posts(target)
except InsufficientCreditsError as exc:
print(f"out of credits: {exc.balance} left, {exc.required} needed")
except RateLimitError as exc:
print(f"slow down for {exc.retry_after}s")
except ScrapierError as exc:
print(f"something else: {exc}")| Exception | When |
|---|---|
ConfigurationError |
no API key, or a reserved parameter was passed |
TransportError |
the request never got a response |
BadRequestError |
400 — bad input |
AuthenticationError |
401 — bad or missing key |
InsufficientCreditsError |
402 with a balance — carries .balance and .required |
NotFoundError |
404 |
RateLimitError |
429 — carries .retry_after |
ScrapeTimeoutError |
504 — the scrape itself ran out of time |
ServiceUnavailableError |
503 |
ServerError |
5xx |
JobFailedError |
a bulk job finished in failed — carries .errors |
APIError |
the base for anything with a status code |
429, 503, 5xx and transport failures are retried automatically with
jittered backoff that honours Retry-After. 400, 401, 404 and a 402
about your balance are not — retrying those only wastes time.
export SCRAPIER_API_KEY=sk_live_...
scrapier-facebook-page-posts <target> --max-items 50 --jsonlJSON on stdout and nothing else, so it pipes. Global flags (--api-key,
--base-url, --timeout, --jsonl, --indent) work anywhere on the
line. Exit codes: 0 success, 2 usage or configuration, 3 API
error.
FacebookPagePosts(
api_key=None, # falls back to $SCRAPIER_API_KEY
base_url=None, # falls back to $SCRAPIER_BASE_URL, then the default
timeout=180.0,
max_retries=3, # for 429/503/5xx and transport failures
http_client=None, # bring your own httpx.Client
)The key is sent in the X-API-Key header only — never in a URL or a
request body, so it will not end up in a proxy log.
Every call also accepts method="GET" if you would rather the
parameters went in the query string, use_proxy=True to route the
scrape through Scrapier's proxy pool, and raw_data=True to get the
upstream payloads instead of parsed rows.
Python 3.9+. The only dependency is httpx. Ships py.typed.
The client code is MIT-licensed. It needs a Scrapier API key, and requests are billed in credits; failed requests are not billed. See pricing. You can start without a credit card.
No. The scrape runs on Scrapier's servers and returns JSON.
Use bulk jobs: submit many inputs as one background job, then job.wait().
Yes. See AGENTS.md, or connect the
Scrapier MCP server.
180+ endpoints across 35+ platforms: browse them all.
Open an issue or read the docs.
MIT. See LICENSE.