kevinzg / facebook-scraper

Scrape Facebook public pages without an API key
MIT License
2.43k stars 631 forks source link

Live Post Exraction #760

Open Ace2RA opened 2 years ago

Ace2RA commented 2 years ago

Regarding to the code in #742, how do I export the pprint output to a json/ccv file?

neon-ninja commented 2 years ago

See https://github.com/kevinzg/facebook-scraper/search?q=json.dump&type=issues for some examples using json.dump. https://github.com/kevinzg/facebook-scraper/search?q=to_csv&type=issues for some examples using pandas to_csv

bullride commented 2 years ago

@Ace2RA Here is the code I'm using to get live posts and save them to json file.

from facebook_scraper import *
import json

with open('yourfilename.json', 'w', encoding='utf8') as f:
   posts = list(get_posts("facebook-page-group", pages=2, cookies="cookies.json",
                          options={"allow_extra_requests": False}))
   json.dump(posts, f, ensure_ascii=False, default=str);

Hope this helps a bit.