Skip to main content

Python package to scrap facebook's pages front end with no limitations

Project description

Facebook Page Scraper

Maintenance PyPI license Python >=3.6.9

No registration, No need of API key, No limitation on number of requests. Import the library and Just Do It !

Prerequisites

  • Internet Connection
  • Python 3.6+
  • Chrome or Firefox browser installed on your machine


Installation:

Installing from source:

git clone https://github.com/shaikhsajid1111/facebook_page_scraper 

Inside project's directory

python3 setup.py install

Installing with pypi

pip3 install facebook-page-scraper


How to use?

#import Facebook_scraper class from facebook_page_scraper
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)

Parameters for Facebook_scraper(page_name,posts_count,browser) class

Parameter Name Parameter Type Description
page_name string name of the facebook page
posts_count integer number of posts to scrap, if not passed default is 10
browser string which browser to use, either chrome or firefox. if not passed,default is chrome



Done with instantiation?. Let the scraping begin!


For post's data in JSON format:

#call the scrap_to_json() method

json_data = facebook_ai.scrap_to_json()
print(json_data)

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": [
            "https://scontent-bom1-2.xx.fbcdn.net/v/t39.2365-6/p540x282/131570013_988138305044034_3894567585410559092_n.png?_nc_cat=109&ccb=2&_nc_sid=eaa83b&_nc_ohc=mAeDelparrEAX-3Mk7E&_nc_ht=scontent-bom1-2.xx&_nc_tp=30&oh=3fedb0e3cea6ad6f934ca20f77bec624&oe=600CB4C9"
        ],
        "post_url": "https://www.facebook.com/facebookai/posts/1730063790503900"
    },    ...

}

Output Structure for JSON format:

{
    "id": {
        "name": string,    
        "shares": integer,
        "reactions": {
            "likes": integer,
            "loves": integer,
            "wow": integer,
            "cares": integer,
            "sad": integer,
            "angry": integer,
            "haha": integer
        },
        "reaction_count": integer,
        "comments": integer,
        "content": string,
        "video" : string,
        "image" : list,
        "posted_on": datetime,  //string containing datetime in ISO 8601
        "post_url": string
    }
}



For saving post's data directly to CSV file

#call scrap_to_csv(filename,directory) method


filename = "data_file"  #file name without CSV extension,where data will be saved
directory = "E:\data" #directory where CSV file will be saved
facebook_ai.scrap_to_csv(filename,directory)

content of data_file.csv:

id,name,shares,likes,loves,wow,cares,sad,angry,haha,reactions_count,comments,content,video,image,post_url
1730063790503900,Facebook AI,62,295,30,6,0,0,0,0,331,10,"We�re 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.",,https://scontent-bom1-2.xx.fbcdn.net/v/t39.2365-6/p540x282/131570013_988138305044034_3894567585410559092_n.png?_nc_cat=109&ccb=2&_nc_sid=eaa83b&_nc_ohc=mAeDelparrEAX9CTY7c&_nc_ht=scontent-bom1-2.xx&_nc_tp=30&oh=c54502f6b0d2063cf455d88d20fe8c57&oe=600CB4C9,https://www.facebook.com/facebookai/posts/1730063790503900

...



Parameters for scrap_to_csv(filename,directory) method.

Parameter Name Parameter Type Description
filename string name of the CSV file where post's data will be saved
directory string directory where CSV file have to be stored.



Keys of the outputs:

Key Type Description
id string Post Identifier(integer casted inside string)
name string Name of the page
shares integer share count of post
reactions dictionary dictionary containing reactions as keys and its count as value. Keys => ["likes","loves","wow","cares","sad","angry","haha"]
reaction_count integer total reaction count of post
comments integer comments count of post
content string content of post as text
video string URL of video present in that post
image list python's list containing URLs of all images present in the post
posted_on datetime time at which post was posted(in ISO 8601 format)
post_url string URL for that post


Privacy

This scraper only scrapes public data available to unauthenticated user and does not holds the capability to scrap anything private.



Tech

This project uses different libraries to work properly.



LICENSE

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

facebook_page_scraper-0.1.3.tar.gz (15.7 kB view hashes)

Uploaded Source

Built Distribution

facebook_page_scraper-0.1.3-py3.9.egg (25.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page