DEV Community

Sajid Shaikh
Sajid Shaikh

Posted on

Scrape Facebook public pages without an API key or limitations

Facebook's API is really difficult to setup and have rate limiting as well. Why not getting public data with some automation?. Here's a python library that does the job.

Install it with pypi:

pip install facebook-page-scraper

Install it from source:
Download it using git:

git clone

and open terminal inside folder and enter command:

python3 install


How to use it?
Well its simple!,
Just import class from the package,instantiate and start scraping.

Suppose I want posts from Facebook AI,

from facebook_page_scraper import Facebook_scraper

#instantiate the Facebook_scraper class

page_name = "facebookai"
posts_count = 10
browser = "firefox"

facebook_ai = Facebook_scraper(page_name,posts_count,browser)
Enter fullscreen mode Exit fullscreen mode

Above was instantiation part, Suppose you want data in JSON format than just call the



json_data = facebook_ai.scrap_to_json()
Enter fullscreen mode Exit fullscreen mode

And you will get the JSON Output:

    "1730063790503900": {
        "name": "Facebook AI",
        "shares": 65,
        "reactions": {
            "likes": 305,
            "loves": 31,
            "wow": 7,
            "cares": 0,
            "sad": 0,
            "angry": 0,
            "haha": 0
        "reaction_count": 343,
        "comments": 11,
        "content": "We\u2019re training computer vision models that leverage Transformers, a deep neural network architecture. Data-efficient image Transformers (DeiT) use less data and computing resources to produce high-performance image classification AI models.  We hope to advance the field of computer vision by sharing this work with the broader community, making large-scale systems that train AI models more accessible to researchers and engineers.",
        "posted_on": "2020-12-24T04:05:27",
        "video": "",
        "image": [
        "post_url": ""
    },    ...

Enter fullscreen mode Exit fullscreen mode

if you want to save the data to CSV file directly, Just call the




filename = "data_file"  #file name without CSV extension,where data will be saved
directory = "E:\data" #directory where CSV file will be saved
Enter fullscreen mode Exit fullscreen mode


CSV output


Top comments (2)

ihabpalamino profile image

hello i have a question for exemple i want to define a period of date that i want to scrape how can i do it? for example i want to scrap since 2023/1/1 until 2023/4/12