-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e5ec22
commit c9ccc60
Showing
6 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
env.json | ||
|
||
# C extensions | ||
*.so | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,37 @@ | ||
# facebook_comment_automation | ||
Your friend just offered to do something silly for commenting in thousands in their post? look no further! You are in the right repo xD | ||
|
||
## overview | ||
It's a simple selenium automation implementation. It logs in your account and then goes to your friends timeline and finds the latest post and starts commenting. | ||
|
||
## Prerequisites | ||
- You will need have Python3 | ||
- Setup virtualenv and install selenium | ||
```console | ||
your_pc$ virtualenv -p /usr/bin/python3 venv | ||
``` | ||
```console | ||
your_pc$ source venv/bin/activate | ||
``` | ||
```console | ||
(venv)your_pc$ pip install selenium | ||
``` | ||
- Have firefox installed | ||
- I used geckodriver for linux. If you run windows, install geckodriver for windows. | ||
- Rename env_sample.json to env.json and configure it with your username,password and target's username | ||
|
||
## Running | ||
You will need to add PATH for geckodriver | ||
```console | ||
(venv)your_pc$ export PATH=$PATH:. | ||
``` | ||
```console | ||
(venv)your_pc$ python main.py | ||
``` | ||
|
||
## Process Steps of the bot | ||
- goes to facebook.com | ||
- logs in to your account | ||
- goes to targets's timeline | ||
- selects latest post | ||
- starts commenting random letters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"username": "john.doe", | ||
"password": "john1234", | ||
"target_username": "john.ulala" | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
from selenium import webdriver | ||
from selenium.common.exceptions import NoSuchElementException | ||
from selenium.webdriver.common.keys import Keys | ||
from selenium.webdriver.firefox.options import Options | ||
import json | ||
import time | ||
import random | ||
import string | ||
import os | ||
|
||
# Opening env.json file | ||
f = open('env.json',) | ||
|
||
# returns JSON object as a dictionary | ||
credentials = json.load(f) | ||
|
||
# Closing file | ||
f.close() | ||
|
||
username = credentials['username'] | ||
password = credentials['password'] | ||
target_username = credentials['target_username'] | ||
|
||
|
||
firefox_options = Options() | ||
firefox_options.add_argument('--dns-prefetch-disable') | ||
firefox_options.add_argument('--no-sandbox') | ||
firefox_options.add_argument('--lang=en-US') | ||
browser = webdriver.Firefox() | ||
|
||
|
||
browser.get('https://www.facebook.com/') | ||
signup_elem = browser.find_element_by_id('email') | ||
signup_elem.send_keys(username) | ||
|
||
login_elem = browser.find_element_by_id('pass') | ||
login_elem.send_keys(password) | ||
|
||
ins = browser.find_elements_by_tag_name('input') | ||
for x in ins: | ||
if x.get_attribute('value') == 'Log In': | ||
x.click() # here logged in | ||
break | ||
|
||
#then key here move to mobile version as that doesn't support javascript | ||
browser.get('https://m.facebook.com/'+target_username+'?v=timeline') | ||
|
||
|
||
# find last post (occurance of comment) | ||
as_el = browser.find_elements_by_tag_name('a') | ||
for a in as_el: | ||
print(a.text) | ||
if 'omment' in a.text.strip(): | ||
a.click() | ||
break | ||
time.sleep(10) | ||
|
||
# it will go for 1000 comments | ||
i = 1000 | ||
while i > 0: | ||
# do actual comment | ||
ins = browser.find_element_by_id('composerInput') | ||
|
||
cmnt = random.choice(string.ascii_letters) # just picked any random letter | ||
|
||
ins.send_keys(cmnt) | ||
# submit input | ||
|
||
ins = browser.find_elements_by_tag_name('input') | ||
for x in ins: | ||
if 'omment' in x.get_attribute('value'): | ||
x.click() | ||
break | ||
|
||
#random waiting | ||
r = random.randrange(2,5) | ||
time.sleep(r) | ||
|
||
i = i - 1 |