kevinzg / facebook-scraper

Scrape Facebook public pages without an API key
MIT License
2.29k stars 616 forks source link

Extract info from exact post? #207

Closed spdimov closed 3 years ago

spdimov commented 3 years ago

Hello, is it possible to extract post info by post URL. I dont want to scrape whole page, just a single post. Thanks!

neon-ninja commented 3 years ago

Yes, here's an example:

from facebook_scraper import get_posts
import pprint
posts = list(get_posts(post_urls=["https://m.facebook.com/story.php?story_fbid=1931709990319458&id=285708024919671"]))
pprint.pprint(posts)

Outputs:

[{'available': True,
  'comments': 0,
  'comments_full': None,
  'factcheck': None,
  'image': 'https://scontent.fakl1-3.fna.fbcdn.net/v/t1.6435-9/fr/cp0/e15/q65/167519232_1931709876986136_319473773610266922_n.jpg?_nc_cat=107&ccb=1-3&_nc_sid=8024bb&_nc_ohc=X9hJWvCGY3EAX-mwyRC&_nc_ht=scontent.fakl1-3.fna&tp=14&oh=eb470e26dada1b4d602e049f6671621f&oe=60A19FA6',
  'images': ['https://scontent.fakl1-3.fna.fbcdn.net/v/t1.6435-9/fr/cp0/e15/q65/167519232_1931709876986136_319473773610266922_n.jpg?_nc_cat=107&ccb=1-3&_nc_sid=8024bb&_nc_ohc=X9hJWvCGY3EAX-mwyRC&_nc_ht=scontent.fakl1-3.fna&tp=14&oh=eb470e26dada1b4d602e049f6671621f&oe=60A19FA6'],
  'is_live': False,
  'likes': 0,
  'link': 'https://www.nintendo.com.au/the-big-multiplayer-sale',
  'post_id': '1931709990319458',
  'post_text': 'Challenge friends and family with a selection of online '
               'multiplayer games, now up to 75% off as part of The Big '
               'Multiplayer Sale!\n'
               '\n'
               'See highlights: '
               'https://www.nintendo.com.au/the-big-multiplayer-sale',
  'post_url': 'https://facebook.com/story.php?story_fbid=1931709990319458&id=285708024919671',
  'reactors': None,
  'shared_post_id': None,
  'shared_post_url': None,
  'shared_text': '',
  'shared_time': None,
  'shared_user_id': None,
  'shared_username': None,
  'shares': 0,
  'text': 'Challenge friends and family with a selection of online multiplayer '
          'games, now up to 75% off as part of The Big Multiplayer Sale!\n'
          '\n'
          'See highlights: '
          'https://www.nintendo.com.au/the-big-multiplayer-sale',
  'time': datetime.datetime(2021, 4, 6, 14, 34, 11),
  'user_id': '285708024919671',
  'username': 'Nintendo',
  'video': None,
  'video_id': None,
  'video_thumbnail': None,
  'w3_fb_url': None}]
spdimov commented 3 years ago

Thank you!