Skip to content

Commit

Permalink
code upload
Browse files Browse the repository at this point in the history
  • Loading branch information
shuhanmirza committed Jul 23, 2020
1 parent 6e5ec22 commit c9ccc60
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
__pycache__/
*.py[cod]
*$py.class
env.json

# C extensions
*.so
Expand Down
35 changes: 35 additions & 0 deletions README.md
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
5 changes: 5 additions & 0 deletions env_sample.json
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 added geckodriver
Binary file not shown.
Binary file added geckodriver-v0.26.0-linux64.tar.gz
Binary file not shown.
79 changes: 79 additions & 0 deletions main.py
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

0 comments on commit c9ccc60

Please sign in to comment.