Code Monkey home page Code Monkey logo

fbscraper's Introduction

fbscraper

Scraping posts, comments and replies from Facebook.

Installing

$ git clone https://github.com/utkarsh512/fbscraper.git
$ cd fbscraper
$ pip install . -r requirements.txt

How to use

Creating a session

Create a Session object for scraping:

from fbscraper import Session
sess = Session(
    credentials=(EMAIL, 
                 PASSWORD), 
    chromeDriverPath="chromedriver"
)

where (EMAIL, PASSWORD) are your facebook credentials and chromeDriverPath is the path to the chromedriver.

Fetching post URLs from the public pages

Then, you can extract recent post URLs of a public pages as

sess.getPage("nytimes")
sess.scroll(10)
postURLs = sess.getPostURLs()

Scraping posts using the fetched URLs

As you now have the list of URLs for the required posts, post data (including comments) can be scraped as

sess.getPost(
    postURL="https://mbasic.facebook.com/story.php?...",
    dump="posts.pkl",
    getComments=True,
    getReplies=True,
    nComments=1000,
    nReplies=10
)

where

  • postURL is the URL of the post
  • dump is the name of binary file used for dumping the post data
  • getComments should be True if you want to scrape comments to the post as well
  • getReplies should be True if you want to scrape replies to the comments as well
  • nComments is the upper-bound on number of comments per post
  • nReplies is the upper-bound on number of replies per comment

Note: Just make sure postURL starts with https://mbasic.facebook.com instead of https://www.facebook.com, https://mobile.facebook.com, etc.

fbscraper's People

Contributors

utkarsh512 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fbscraper's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.