Implement Facebook scraper for post data retrieval
Project description
Facebook Graphql Scraper
Install
To install the latest release from PyPI:
pip install facebook-graphql-scraper
Or, to install the latest master branch:
pip install git+https://github.com/faustren/facebook-graphql-scraper.git
Usage
You can choose between two methods to collect user posts data.
- Log in with your account credentials: login facebook account
- Without logging in: Without logging in, click the X icon to
- Difference: The difference between these two methods is that for some personal accounts, you cannot browse the user's posts without logging into a Facebook account.
from facebook_graphql_scraper import FacebookGraphqlScraper as fb_graphql_scraper
from dotenv import load_dotenv
import os
## Load account info
load_dotenv()
username_or_userid = os.getenv("FB_USERNAME_OR_USERID")
pwd = os.getenv("FBPASSWORD")
#%%
## Log in account version
fb_user_id = "KaiCenatOfficial"
url = "https://www.facebook.com/"
res = fb_graphql_scraper.get_user_posts(
fb_username_or_userid=fb_user_id,
loop_times=50,
username_or_userid=username_or_userid,
pwd=pwd
)
res
#%%
## Without logging in account version
fb_user_id = "KaiCenatOfficial"
url = "https://www.facebook.com/"
res = fb_graphql_scraper.get_user_posts(
fb_username_or_userid=fb_user_id,
loop_times=50
)
res
Optional parameters
- fb_user_id: group id/fans page id/account id.
- timeout: How many seconds to wait before timing out. Default is 600.
- looptimes: The program scrolls down Facebook pages..
Post example
[{'post_id': '385393337713956',
'post_url': 'https://www.facebook.com/385393337713956',
'username_or_userid': 'KaiCenatOfficial',
'published_date': Timestamp('2024-03-31 16:00:39'),
'published_date2': '2024-03-31',
'time': 1711900839,
'reaction_count.count': 1224,
'comment_rendering_instance.comments.total_count': 37,
'share_count.count': 32,
'sub_reactions': {'讚': 802,
'哈': 406,
'大心': 9,
'怒': 3,
'加油': 2,
'哇': 2,
'嗚': '0'},
'context': 'Druski Plays "What\'s In The Box?" 😱',
'video_view_count': 15870},
{'post_id': '387206327532657',
'post_url': 'https://www.facebook.com/387206327532657',
'username_or_userid': 'KaiCenatOfficial',
'published_date': Timestamp('2024-03-30 12:01:06'),
'published_date2': '2024-03-30',
'time': 1711800066,
'reaction_count.count': 7153,
'comment_rendering_instance.comments.total_count': 154,
'share_count.count': 67,
'sub_reactions': {'讚': 5674,
'哈': 1307,
'大心': 121,
'嗚': 22,
'加油': 21,
'哇': 8,
'怒': '0'},
'context': 'Kai Cenat Asks Tyla Out On A Date 😍 #viralreelsfb #comedy #kaicenat #reelsfb',
'video_view_count': 73898},
{'post_id': '385387707714519',
'post_url': 'https://www.facebook.com/385387707714519',
'username_or_userid': 'KaiCenatOfficial',
'published_date': Timestamp('2024-03-29 17:01:39'),
'published_date2': '2024-03-29',
'time': 1711731699,
'reaction_count.count': 1000,
'comment_rendering_instance.comments.total_count': 47,
'share_count.count': 15,
'sub_reactions': {'讚': 762,
'哈': 194,
'大心': 34,
'哇': 7,
'加油': 2,
'嗚': 1,
'怒': '0'},
'context': 'Chunkz Gets Hypnotised 😱',
'video_view_count': 13763},
{'post_id': '384078261178797',
'post_url': 'https://www.facebook.com/384078261178797',
'username_or_userid': 'KaiCenatOfficial',
'published_date': Timestamp('2024-03-28 17:00:21'),
'published_date2': '2024-03-28',
'time': 1711645221,
'reaction_count.count': 2587,
'comment_rendering_instance.comments.total_count': 77,
'share_count.count': 45,
'sub_reactions': {'讚': 1905,
'哈': 477,
'大心': 186,
'加油': 15,
'哇': 4,
'怒': '0',
'嗚': '0'},
'context': 'Trying The New Ice Spice Drink 😳',
'video_view_count': 125605}
]
Notes
- If you choose to collect data by logging into your account, you may face the risk of your account being blocked, even if this program only scrolls through Facebook web pages.
- Reaction Categories (EN): [
like
,love
,haha
,sorry
,wow
,angry
,care
] - Reaction Categories (TW): [
讚
,哈
,怒
,大心
,加油
,哇
,嗚
]
## To-Do
- Collect profile info
- Collect image info
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
Built Distribution
Close
Hashes for facebook-graphql-scraper-0.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37e9bd8867073f7a2679e10c4b912dd9381ade9c1994af20abb2ed256401e814 |
|
MD5 | f2d53ae202989043822a753359c0abb6 |
|
BLAKE2b-256 | a4cbe7f10ed50b26c8d526fd7c0651bf135f9145a383cad29018e44b26be4726 |
Close
Hashes for facebook_graphql_scraper-0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c0ae17f9e9dea809c862ae39ff20ae8d41e80c3fbec79df1f7d03520826d41b |
|
MD5 | d481197bc95ebc5f5affdfd988f97da4 |
|
BLAKE2b-256 | 26a7c36f62667c0ba50ceb11d4a7659846349e3ce0dad4fdfefded65782b21ab |