kevinzg / facebook-scraper

Scrape Facebook public pages without an API key
MIT License
2.4k stars 627 forks source link

How to extract posts from a community page? #787

Open rohullaa opened 2 years ago

rohullaa commented 2 years ago

Hi. I am trying to scrape posts from the community page of a username. For example: https://www.facebook.com/UberEU/community/

How can I do it with facebook_scraper?

neon-ninja commented 2 years ago

Try:

from pprint import pprint
from facebook_scraper import _scraper
from facebook_scraper import *

set_cookies("cookies.json")
for post in get_posts("UberEU/community"):
    pprint(post)

For me, this gives output like the following:

{'available': True,
 'comments': 0,
 'comments_full': None,
 'factcheck': None,
 'header': 'Andrija Andrews\u200eUber',
 'image': 'https://scontent.fakl8-1.fna.fbcdn.net/v/t39.30808-6/290887258_2195749617251515_4091579574107070154_n.jpg?stp=cp0_dst-jpg_e15_fr_q65&_nc_cat=103&ccb=1-7&_nc_sid=de0e5b&efg=eyJpIjoidCJ9&_nc_ohc=44nIy8s4loQAX_Spchd&_nc_ht=scontent.fakl8-1.fna&oh=00_AT-OAdoxFaSggn7eAjefChKYzAlQ8eec4T37IlPVna894w&oe=62BFA12E&manual_redirect=1',
 'image_id': None,
 'image_ids': [],
 'image_lowquality': 'https://scontent.fakl8-1.fna.fbcdn.net/v/t39.30808-6/290887258_2195749617251515_4091579574107070154_n.jpg?stp=cp0_dst-jpg_e15_q65_s526x395&_nc_cat=103&ccb=1-7&_nc_sid=de0e5b&efg=eyJpIjoidCJ9&_nc_ohc=44nIy8s4loQAX_Spchd&_nc_ht=scontent.fakl8-1.fna&oh=00_AT81KHXHzAzMH3RsGMfRxY2e1Uhv29JCg8J0dBtl-8KsQw&oe=62BFA12E',
 'images': ['https://scontent.fakl8-1.fna.fbcdn.net/v/t39.30808-6/290887258_2195749617251515_4091579574107070154_n.jpg?stp=cp0_dst-jpg_e15_fr_q65&_nc_cat=103&ccb=1-7&_nc_sid=de0e5b&efg=eyJpIjoidCJ9&_nc_ohc=44nIy8s4loQAX_Spchd&_nc_ht=scontent.fakl8-1.fna&oh=00_AT-OAdoxFaSggn7eAjefChKYzAlQ8eec4T37IlPVna894w&oe=62BFA12E&manual_redirect=1',
            'https://scontent.fakl8-1.fna.fbcdn.net/v/t39.30808-6/290893078_2195749573918186_7202274568545747293_n.jpg?stp=cp0_dst-jpg_e15_fr_q65&_nc_cat=101&ccb=1-7&_nc_sid=de0e5b&efg=eyJpIjoidCJ9&_nc_ohc=Xu57Fvlp4QAAX9asiog&_nc_ht=scontent.fakl8-1.fna&oh=00_AT8WVkcubYFzQ956FGFvnGSxvnTlJ1LnYkzJjbKeF5yURA&oe=62BF44BA&manual_redirect=1',
            'https://scontent.fakl8-1.fna.fbcdn.net/v/t39.30808-6/290643101_2195749593918184_7315196984805201350_n.jpg?stp=cp0_dst-jpg_e15_fr_q65&_nc_cat=104&ccb=1-7&_nc_sid=de0e5b&efg=eyJpIjoidCJ9&_nc_ohc=sbnonJafgqsAX_2j0HL&tn=iGTasn8pTzY0Dad4&_nc_ht=scontent.fakl8-1.fna&oh=00_AT9U-RHjPifkTpoMP8tpclyPFqGp2gk5g45elg9d_-1T2A&oe=62BFEAC3&manual_redirect=1'],
 'images_description': ['May be an image of 1 person, map and text that says '
                        "'16:08 6.4 miles away Jecenice Gata Pick-up spot 70 "
                        'Dugi Rat Omis Google Meet at the pickup point for ul. '
                        'Josipa Pupačića 4 14 min 4.9 ZG7856IR White Renault '
                        "Megane Domagoj 1,086 trips Message Domagoj'",
                        'May be an image of 1 person and text that says '
                        "'Drop-off at Marineta ulica E Drop-off by 17:22 "
                        'Marineta ulica Add or change ዳ HRK317.85 Visa 7002 '
                        "Switch Riding with someone? Split fare Cancel'",
                        "May be an image of \u200etext that says '\u200e16:36 "
                        '54 Trip details Pupačića Pupačića Josipa .اله Google '
                        'Mulo Vukovarskaul Jurja Šubiéa 27/06/22, 16:07 Map '
                        'data ©2022 HRK0.00 Driver did not confirm trip Cesta '
                        'Mutogras 81, 21312, Podstrana, Croatia Put Mlija 1, '
                        '21310, Omiš, Croatia Receipt Your trip with Domagoj '
                        'Find Lost Item We can help you get in touch with your '
                        "driver\u200e'\u200e"],
 'images_lowquality': ['https://scontent.fakl8-1.fna.fbcdn.net/v/t39.30808-6/290887258_2195749617251515_4091579574107070154_n.jpg?stp=cp0_dst-jpg_e15_q65_s526x395&_nc_cat=103&ccb=1-7&_nc_sid=de0e5b&efg=eyJpIjoidCJ9&_nc_ohc=44nIy8s4loQAX_Spchd&_nc_ht=scontent.fakl8-1.fna&oh=00_AT81KHXHzAzMH3RsGMfRxY2e1Uhv29JCg8J0dBtl-8KsQw&oe=62BFA12E',
                       'https://scontent.fakl8-1.fna.fbcdn.net/v/t39.30808-6/290893078_2195749573918186_7202274568545747293_n.jpg?stp=cp0_dst-jpg_e15_p110x80_q65&_nc_cat=101&ccb=1-7&_nc_sid=de0e5b&efg=eyJpIjoidCJ9&_nc_ohc=Xu57Fvlp4QAAX9asiog&_nc_ht=scontent.fakl8-1.fna&oh=00_AT93aWwWItrms7A46yjDKdx92eke2pdy7-1rZklowGnALQ&oe=62BF44BA',
                       'https://scontent.fakl8-1.fna.fbcdn.net/v/t39.30808-6/290643101_2195749593918184_7315196984805201350_n.jpg?stp=cp0_dst-jpg_e15_p110x80_q65&_nc_cat=104&ccb=1-7&_nc_sid=de0e5b&efg=eyJpIjoidCJ9&_nc_ohc=sbnonJafgqsAX_2j0HL&tn=iGTasn8pTzY0Dad4&_nc_ht=scontent.fakl8-1.fna&oh=00_AT-dEtOqhubOxDIoIm-HosZExK5qi4nmGZSsOicE03dq5A&oe=62BFEAC3'],
 'images_lowquality_description': ['May be an image of 1 person, map and text '
                                   "that says '16:08 6.4 miles away Jecenice "
                                   'Gata Pick-up spot 70 Dugi Rat Omis Google '
                                   'Meet at the pickup point for ul. Josipa '
                                   'Pupačića 4 14 min 4.9 ZG7856IR White '
                                   'Renault Megane Domagoj 1,086 trips Message '
                                   "Domagoj'",
                                   'May be an image of 1 person and text that '
                                   "says 'Drop-off at Marineta ulica E "
                                   'Drop-off by 17:22 Marineta ulica Add or '
                                   'change ዳ HRK317.85 Visa 7002 Switch Riding '
                                   "with someone? Split fare Cancel'",
                                   'May be an image of \u200etext that says '
                                   "'\u200e16:36 54 Trip details Pupačića "
                                   'Pupačića Josipa .اله Google Mulo '
                                   'Vukovarskaul Jurja Šubiéa 27/06/22, 16:07 '
                                   'Map data ©2022 HRK0.00 Driver did not '
                                   'confirm trip Cesta Mutogras 81, 21312, '
                                   'Podstrana, Croatia Put Mlija 1, 21310, '
                                   'Omiš, Croatia Receipt Your trip with '
                                   'Domagoj Find Lost Item We can help you get '
                                   "in touch with your driver\u200e'\u200e"],
 'is_live': False,
 'likes': 0,
 'link': None,
 'links': [],
 'original_text': None,
 'page_id': None,
 'post_id': '768773284556116',
 'post_text': 'Unprofessional to a level one can not even imagine! Accepts the '
              'ride which I ordered on behalf of someone else. Starts and '
              'cancels so he could charge in cash and the whole point of this '
              'was to avoid cash payment! Poor reaction from Uber customer '
              'service as well!',
 'post_url': 'https://facebook.com/UberEU/community/posts/768773284556116',
 'reaction_count': None,
 'reactions': None,
 'reactors': None,
 'shared_post_id': None,
 'shared_post_url': None,
 'shared_text': '',
 'shared_time': None,
 'shared_user_id': None,
 'shared_username': None,
 'sharers': None,
 'shares': 0,
 'text': 'Unprofessional to a level one can not even imagine! Accepts the ride '
         'which I ordered on behalf of someone else. Starts and cancels so he '
         'could charge in cash and the whole point of this was to avoid cash '
         'payment! Poor reaction from Uber customer service as well!',
 'time': datetime.datetime(2022, 6, 27, 14, 0),
 'timestamp': None,
 'user_id': '100004494942912',
 'user_url': 'https://facebook.com/andrija.andrews?__tn__=C-R',
 'username': 'Andrija Andrews',
 'video': None,
 'video_duration_seconds': None,
 'video_height': None,
 'video_id': None,
 'video_ids': [],
 'video_quality': None,
 'video_size_MB': None,
 'video_thumbnail': None,
 'video_watches': None,
 'video_width': None,
 'videos': [],
 'w3_fb_url': None,
 'was_live': False,
 'with': [{'link': '/UberEU/?__tn__=C-R', 'name': 'Uber'}]}