Skip to main content

Scrape Facebook public pages without an API key

Project description

Facebook Scraper

Scrape Facebook public pages without an API key. Inspired by twitter-scraper.

Install

pip install facebook-scraper

Usage

Send the unique page name as the first parameter and you're good to go:

>>> from facebook_scraper import get_posts

>>> for post in get_posts('nintendo', pages=1):
...     print(post['text'][:50])
...
The final step on the road to the Super Smash Bros
Were headed to PAX East 3/28-3/31 with new games

Optional parameters

(For the get_posts function).

  • group: group id, to scrape groups instead of pages. Default is None.
  • pages: how many pages of posts to request, the first 2 pages may have no results, so try with a number greater than 2. Default is 10.
  • timeout: how many seconds to wait before timing out. Default is 5.
  • credentials: tuple of user and password to login before requesting the posts. Default is None.
  • extra_info: bool, if true the function will try to do an extra request to get the post reactions. Default is False.
  • youtube_dl: bool, use Youtube-DL for (high-quality) video extraction. You need to have youtube-dl installed on your environment. Default is False.

CLI usage

$ facebook-scraper --filename nintendo_page_posts.csv --pages 10 nintendo

Run facebook-scraper --help for more details on CLI usage.

Note: If you get a UnicodeEncodeError try adding --encoding utf-8.

Post example

{'post_id': '2257188721032235',
 'text': 'Don’t let this diminutive version of the Hero of Time fool you, '
         'Young Link is just as heroic as his fully grown version! Young Link '
         'joins the Super Smash Bros. series of amiibo figures!',
 'time': datetime.datetime(2019, 4, 29, 12, 0, 1),
 'image': 'https://scontent.flim16-1.fna.fbcdn.net'
          '/v/t1.0-0/cp0/e15/q65/p320x320'
          '/58680860_2257182054366235_1985558733786185728_n.jpg'
          '?_nc_cat=1&_nc_ht=scontent.flim16-1.fna'
          '&oh=31b0ba32ec7886e95a5478c479ba1d38&oe=5D6CDEE4',
 'images': ['https://scontent.flim16-1.fna.fbcdn.net'
          '/v/t1.0-0/cp0/e15/q65/p320x320'
          '/58680860_2257182054366235_1985558733786185728_n.jpg'
          '?_nc_cat=1&_nc_ht=scontent.flim16-1.fna'
          '&oh=31b0ba32ec7886e95a5478c479ba1d38&oe=5D6CDEE4'],
 'likes': 2036,
 'comments': 214,
 'shares': 0,
 'reactions': {'like': 135, 'love': 64, 'haha': 10, 'wow': 4, 'anger': 1},  # if `extra_info` was set
 'post_url': 'https://m.facebook.com/story.php'
             '?story_fbid=2257188721032235&id=119240841493711',
 'link': 'https://bit.ly/something', 
 'is_live': False}

Notes

  • There is no guarantee that every field will be extracted (they might be None).
  • Shares doesn't seem to work at the moment.
  • Group posts may be missing some fields like time and post_url.
  • Group scraping may return only one page and not work on private groups.

To-Do

  • Async support
  • Image galleries (images entry)
  • Profiles or post authors
  • Comments (with options={'comments': True})

Alternatives and related projects

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

facebook-scraper-0.2.27.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

facebook_scraper-0.2.27-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file facebook-scraper-0.2.27.tar.gz.

File metadata

  • Download URL: facebook-scraper-0.2.27.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.5 CPython/3.9.2 Linux/5.10.23-1-MANJARO

File hashes

Hashes for facebook-scraper-0.2.27.tar.gz
Algorithm Hash digest
SHA256 633cf979279c44fdc8aa05b90ac696b9a4479b594dfbf7f413da4de549904b7c
MD5 05625a139d2b710039bcc1d0eaf5aad8
BLAKE2b-256 3b7390d7d01c3cf84b9552565a10430af65001dd1201c10f25b51673dd3c79ee

See more details on using hashes here.

File details

Details for the file facebook_scraper-0.2.27-py3-none-any.whl.

File metadata

  • Download URL: facebook_scraper-0.2.27-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.5 CPython/3.9.2 Linux/5.10.23-1-MANJARO

File hashes

Hashes for facebook_scraper-0.2.27-py3-none-any.whl
Algorithm Hash digest
SHA256 a417cecbb9a9495a6a507d8ff2b842f7b9f792475a7da8a9ba58e58e34a55e91
MD5 47ad6c206378391b9fa89e4a38968c0d
BLAKE2b-256 d7eeeda79cf6c502c1ea4aba1892794e526d58d6ddd4e9e89e67d4f5ee2c41ea

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page