Deen Freelon maintains a great Python script, called fb_scrape_public, for collecting research data in a structured format from Facebook. Freelon himself, apart from working with coding and computational methods to extract and analyse digital datasets, has done lots of interesting stuff such as a 2016 report on #blacklivesmatter and online struggles for offline justice. The fb_scrape_public script has been updated regularly to respond to changes in the Facebook API. For the time being [April 2017], this is how the script can be run:
- Download it from GitHub.
- In spite of some previous instructions, don't edit anything inside the script itself. Just put it in a directory.
- Create your own Facebook app at: https://developers.facebook.com/apps . It doesn't matter what you call it, you just need to pull the unique client ID (app ID) and app secret for your new app.
- From within the fb_scrape_public directory, open a Python 3 shell in Terminal. The code below — if you replace AppID and AppSecret with the keys for your own app, and FacebookID with the ID of the page/group/profile you want to scrape — will collect data into a csv file. If needed, get the FacebookIDs from here.
>>> from fb_scrape_public import scrape_fb >>> fsp = scrape_fb('AppID','AppSecret','FacebookID')
If you use this tool in publications, make sure to cite it: