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.7.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b416fc45483f2f0c95799c068ab1b2da4c838b1a7f8e70407f3b066b67e2ca6 |
|
MD5 | f3a94029c171648ae6356d8155625c54 |
|
BLAKE2b-256 | c146a771336fe9777df4f17bba88dca088950c9fe6221beb08b64d1d8f004a60 |
Close
Hashes for facebook_graphql_scraper-0.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d69bd6a3b20c43e8ac5d69c7328b60ac5f0e01d8f5ee622bba1ba95151b34de2 |
|
MD5 | 9ca92d280ea181cac4629cd1b2ef3e9e |
|
BLAKE2b-256 | 5ed0872c079688e6d9e461a26726f659bd00e16b1535bdc9d7e7fb565442a5da |