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)