DEV Community

mhloo
mhloo

Posted on

Facebook GraphQL Scraper — Open-Source, Lightweight, No Headless Browser

🚀 I built an open-source Facebook GraphQL scraper — no API key required.

A lot of free, open-source Facebook scrapers are outdated or no longer work reliably. I built facebook-gql-scraper to provide a lightweight alternative for developers who need to work with Facebook data.

It supports scraping:

  • 👤 Profiles and user posts
  • 💬 Comments and reactions
  • 👥 Groups
  • 🛍️ Marketplace
  • 🔎 Search results
  • 📸 Photos, videos, and reels

Install it:

pip install facebook-gql-scraper
Enter fullscreen mode Exit fullscreen mode

Get started:

🔑 Export your Facebook cookies as JSON using Cookie-Editor (Firefox) or EditThisCookie (Chrome), then save as facebook_cookies.json.

import facebook_gql_scraper as fgs

ctx = fgs.FacebookContext(cookies_file="facebook_cookies.json")

user = fgs.Profile.from_username(ctx, username="Ishowspeed")

print(user.name, user.biography, user.birthday)

for post in user.get_posts():
    print(post.id, post.text)
Enter fullscreen mode Exit fullscreen mode

Want to retrieve comments, reactions, photos, videos, or other supported data? There's more to explore.

🔗 GitHub: https://github.com/XD-MHLOO/facebook-gql-scraper

It's open source, and feedback, contributions are welcome!

If you're working on Facebook data collection with Python, give it a try and let me know what you think.

Top comments (0)