A Python & Playwright-based automation tool for posting content to multiple Facebook groups automatically.
Note: If you have any questions, feel free to contact me directly.
poc.mp4
- Automates Facebook login and group posting.
- Supports multiple groups via a
groups.jsonconfiguration file. - Allows custom post content.
- Stores and reuses Facebook session cookies to avoid logging in every time.
- Install Python 3.9+.
- Install dependencies:
pip install playwright playwright install chromium
If this is your first time running the script, you need to log in and generate your cookie:
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
self.browser = p.chromium.launch(
headless=False,
channel='chrome',
args=['--start-maximized']
)
self.context = self.browser.new_context(no_viewport=True)
self.page = self.context.new_page()
# First-time login
self.generate_cookie()
# self.load_cookie()
# self.post_to_groups()This will open a Chrome window where you can log in to your Facebook account. Once you log in successfully, cookies will be saved for future runs.
For subsequent runs, load the saved cookie and start posting automatically:
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
self.browser = p.chromium.launch(
headless=False,
channel='chrome',
args=['--start-maximized']
)
self.context = self.browser.new_context(no_viewport=True)
self.page = self.context.new_page()
# Load saved session
self.load_cookie()
self.post_to_groups()Edit the POST_CONTENT variable in your script to customize the post:
POST_CONTENT = f"""
Hello everyone,
Automated post: {now.strftime("%H:%M:%S")}
https://youtu.be/BdjZFPTONYc
"""Edit groups.json to define the groups you want to post in:
[
{
"name": "Алгоритм",
"username": "algorithmicsmn",
"status": "straight"
},
{
"name": "Next.js developers of Mongolia",
"username": "nextjs.developers.of.mongolia",
"status": "straight"
}
]- status:
- "straight" → Post will be uploaded directly.
- "pending" → Post will be sent for admin approval.
This project is for educational purposes only. Use at your own risk. Automating Facebook actions may violate their terms of service, and your account could be restricted or banned.