diff --git a/.gitignore b/.gitignore index b6e4761..2d06679 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ __pycache__/ *.py[cod] *$py.class +env.json # C extensions *.so diff --git a/README.md b/README.md index d7ce317..4a63485 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/env_sample.json b/env_sample.json new file mode 100644 index 0000000..c6f7124 --- /dev/null +++ b/env_sample.json @@ -0,0 +1,5 @@ +{ + "username": "john.doe", + "password": "john1234", + "target_username": "john.ulala" +} \ No newline at end of file diff --git a/geckodriver b/geckodriver new file mode 100755 index 0000000..ff08a41 Binary files /dev/null and b/geckodriver differ diff --git a/geckodriver-v0.26.0-linux64.tar.gz b/geckodriver-v0.26.0-linux64.tar.gz new file mode 100644 index 0000000..d4092ad Binary files /dev/null and b/geckodriver-v0.26.0-linux64.tar.gz differ diff --git a/main.py b/main.py new file mode 100644 index 0000000..1c56174 --- /dev/null +++ b/main.py @@ -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