Skip to content

Commit 9f19b9a

Browse files
Merge pull request avinashkranjan#797 from Amit366/Amit1
Facebook bot
2 parents b40033d + a91c14e commit 9f19b9a

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

Automate Facebook bot/Readme.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# <b>Automate Facebook bot</b>
2+
3+
[![forthebadge](https://forthebadge.com/images/badges/made-with-python.svg)](https://forthebadge.com)
4+
5+
## Automate Facebook bot Functionalities : 🚀
6+
7+
- On running the script it posts your message in the groups whose id is given by the user
8+
9+
## Automate Facebook bot Instructions: 👨🏻‍💻
10+
11+
### Step 1:
12+
13+
Open Termnial 💻
14+
15+
### Step 2:
16+
17+
Locate to the directory where python file is located 📂
18+
19+
### Step 3:
20+
21+
Run the command: python script.py/python3 script.py 🧐
22+
23+
### Step 4:
24+
25+
Sit back and Relax. Let the Script do the Job. ☕
26+
27+
### Requirements
28+
29+
- pyautogui
30+
- time
31+
32+
## Author
33+
34+
Amit Kumar Mishra
35+

Automate Facebook bot/script.py

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import pyautogui
2+
import time
3+
import webbrowser
4+
from selenium import webdriver
5+
from time import sleep
6+
from webdriver_manager.chrome import ChromeDriverManager
7+
from getpass import getpass
8+
9+
10+
LOGIN_URL = 'https://www.facebook.com/login.php'
11+
num = str (input ("Enter group ids separated by commas: "))
12+
lists = num.split (",")
13+
groupid = []
14+
for i in lists:
15+
groupid.append(i)
16+
17+
18+
message=input("Enter your message: ")
19+
20+
class FacebookLogin():
21+
def __init__(self, email, password, browser='Chrome'):
22+
# Store credentials for login
23+
self.email = email
24+
self.password = password
25+
if browser == 'Chrome':
26+
# Use chrome
27+
self.driver = webdriver.Chrome(executable_path=ChromeDriverManager().install())
28+
self.driver.get(LOGIN_URL)
29+
time.sleep(1) # Wait for some time to load
30+
31+
32+
def login(self):
33+
email_element = self.driver.find_element_by_id('email')
34+
email_element.send_keys(self.email) # Give keyboard input
35+
36+
password_element = self.driver.find_element_by_id('pass')
37+
password_element.send_keys(self.password) # Give password as input too
38+
39+
login_button = self.driver.find_element_by_id('loginbutton')
40+
login_button.click() # Send mouse click
41+
42+
time.sleep(2) # Wait for 2 seconds for the page to show up
43+
44+
for i in range(len(groupid)):
45+
link = 'https://facebook.com/groups/'+groupid[i]
46+
self.driver.get(link)
47+
print("Waiting for few seconds .......")
48+
time.sleep(45)
49+
self.driver.find_element_by_class_name('a8c37x1j ni8dbmo4 stjgntxs l9j0dhe7').click()
50+
time.sleep(7)
51+
52+
self.driver.switch_to.active_element.send_keys("message")
53+
time.sleep(7)
54+
55+
self.driver.find_element_by_class_name('a8c37x1j ni8dbmo4 stjgntxs l9j0dhe7 ltmttdrg g0qnabr5').click()
56+
time.sleep(7)
57+
58+
59+
if __name__ == '__main__':
60+
# Enter your login credentials here
61+
usr=input('Enter Email Id:')
62+
pwd= getpass('Enter Password:')
63+
fb_login = FacebookLogin(email=usr, password=pwd, browser='Chrome')
64+
fb_login.login()
65+
66+
#time.sleep(5)
67+
68+

0 commit comments

Comments
 (0)