From 5367f424f0a76b4cf9dfc5f0b717312c6fe0e987 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Tue, 21 May 2019 02:52:17 -0400 Subject: [PATCH 1/3] Add option for headless mode update README with instructions on chromedriver Minor refactor and reformatting - Tighten whitespace - Remove superfluous `assert` statement Minor refactoring and reformatting Fix missing whitespace between = Update deletefb.py Remove git stuff --- README.md | 4 +-- deletefb/deletefb.py | 78 ++++++++++++++++++++++++++++++-------------- 2 files changed, 55 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 86ab71b..ce4bde2 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,8 @@ Personally, I did this so I would feel less attached to my Facebook profile ## How To Use -* Make sure that you have Google Chrome installed and that it is up to date, as - well as the chromedriver for Selenium. See [here](https://sites.google.com/a/chromium.org/chromedriver/downloads). On Arch Linux you can find this in the `chromium` package, but it will vary by OS. +* Make sure that you have Google Chrome installed and that it is up to date +* Also install the chromedriver for Selenium. See [here](https://sites.google.com/a/chromium.org/chromedriver/downloads). On Arch Linux you can find this in the `chromium` package, and on Ubuntu it is `chromium-chromedriver`. * `pip3 install --user delete-facebook-posts` * `deletefb -E "youremail@example.org" -P "yourfacebookpassword" -U "https://www.facebook.com/your.profile.url"` * The script will log into your Facebook account, go to your profile page, and diff --git a/deletefb/deletefb.py b/deletefb/deletefb.py index bd552cc..6b78fe5 100755 --- a/deletefb/deletefb.py +++ b/deletefb/deletefb.py @@ -10,32 +10,55 @@ MAX_POSTS = 5000 def run_delete(): parser = argparse.ArgumentParser() - parser.add_argument("-E", - "--email", - default=None, - help="Your email address associated with the account") - - parser.add_argument("-P", - "--password", - default=None, - help="Your Facebook password") - - parser.add_argument("-U", - "--profile-url", - default=None, - help=""" - The link to your Facebook profile, e.g. https://www.facebook.com/your.name - """) + parser.add_argument( + "-E", + "--email", + required=True, + dest="email", + type=str, + help="Your email address associated with the account" + ) + + parser.add_argument( + "-P", + "--password", + required=True, + dest="password", + type=str, + help="Your Facebook password" + ) + + parser.add_argument( + "-U", + "--profile-url", + required=True, + dest="profile_url", + type=str, + help="The link to your Facebook profile, e.g. https://www.facebook.com/your.name" + ) + + parser.add_argument( + "-H", + "--headless", + action="store_true", + dest="is_headless", + default=False, + help="Run browser in headless mode (no gui)" + ) args = parser.parse_args() - delete_posts(user_email_address=args.email, - user_password=args.password, - user_profile_url=args.profile_url) - -def delete_posts(user_email_address=None, - user_password=None, - user_profile_url=None): + delete_posts( + user_email_address=args.email, + user_password=args.password, + user_profile_url=args.profile_url, + is_headless=args.is_headless + ) + +def delete_posts(user_email_address, + user_password, + user_profile_url, + is_headless): """ user_email_address: Your Email user_password: Your password @@ -50,10 +73,15 @@ def delete_posts(user_email_address=None, chrome_options = Options() prefs = {"profile.default_content_setting_values.notifications" : 2} chrome_options.add_experimental_option("prefs", prefs) - chrome_options.add_argument("start-maximized") - driver = Chrome(chrome_options=chrome_options) + if is_headless: + chrome_options.add_argument('--headless') + chrome_options.add_argument('--disable-gpu') + chrome_options.add_argument('--no-sandbox') + chrome_options.add_argument('log-level=2') + + driver = Chrome(options=chrome_options) driver.implicitly_wait(10) driver.get("https://facebook.com") -- 2.30.2 From a8117619282f2b667fcf0d0c5ab83ddedad62cc3 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Tue, 21 May 2019 06:46:31 -0400 Subject: [PATCH 2/3] Remove --no-sandbox flag --- deletefb/deletefb.py | 1 - 1 file changed, 1 deletion(-) diff --git a/deletefb/deletefb.py b/deletefb/deletefb.py index 6b78fe5..8cd0f49 100755 --- a/deletefb/deletefb.py +++ b/deletefb/deletefb.py @@ -78,7 +78,6 @@ def delete_posts(user_email_address, if is_headless: chrome_options.add_argument('--headless') chrome_options.add_argument('--disable-gpu') - chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('log-level=2') driver = Chrome(options=chrome_options) -- 2.30.2 From 0f9d1fcb9d7a180f95f856a955cb8ab060dcbede Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Tue, 21 May 2019 01:59:45 -0400 Subject: [PATCH 3/3] Minor refactoring and reformatting :) --- deletefb/deletefb.py | 106 +++++++++++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 40 deletions(-) diff --git a/deletefb/deletefb.py b/deletefb/deletefb.py index bd552cc..231adf6 100755 --- a/deletefb/deletefb.py +++ b/deletefb/deletefb.py @@ -1,78 +1,100 @@ #! /usr/bin/env python +import argparse +import time + from seleniumrequests import Chrome from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.chrome.options import Options -import time -import argparse + MAX_POSTS = 5000 def run_delete(): parser = argparse.ArgumentParser() - parser.add_argument("-E", - "--email", - default=None, - help="Your email address associated with the account") - - parser.add_argument("-P", - "--password", - default=None, - help="Your Facebook password") - - parser.add_argument("-U", - "--profile-url", - default=None, - help=""" - The link to your Facebook profile, e.g. https://www.facebook.com/your.name - """) + parser.add_argument( + "-E", + "--email", + required=True, + dest="email", + type=str, + help="Your email address associated with the account" + ) + + parser.add_argument( + "-P", + "--password", + required=True, + dest="password", + type=str, + help="Your Facebook password" + ) + + parser.add_argument( + "-U", + "--profile-url", + required=True, + dest="profile_url", + type=str, + help="The link to your Facebook profile, e.g. https://www.facebook.com/your.name" + ) + + parser.add_argument( + "-H", + "--headless", + action="store_true", + dest="is_headless", + default=False, + help="Run browser in headless mode (no gui)" + ) args = parser.parse_args() - delete_posts(user_email_address=args.email, - user_password=args.password, - user_profile_url=args.profile_url) - -def delete_posts(user_email_address=None, - user_password=None, - user_profile_url=None): + delete_posts( + user_email_address=args.email, + user_password=args.password, + user_profile_url=args.profile_url, + is_headless=args.is_headless + ) + +def delete_posts(user_email_address, + user_password, + user_profile_url, + is_headless): """ - user_email_address: Your Email - user_password: Your password - user_profile_url: Your profile URL + user_email_address: str Your Email + user_password: str Your password + user_profile_url: str Your profile URL """ - - assert all((user_email_address, - user_password, - user_profile_url)), "Insufficient arguments provided" - # The Chrome driver is required because Gecko was having issues chrome_options = Options() - prefs = {"profile.default_content_setting_values.notifications" : 2} + prefs = {"profile.default_content_setting_values.notifications": 2, 'disk-cache-size': 4096} chrome_options.add_experimental_option("prefs", prefs) - chrome_options.add_argument("start-maximized") - driver = Chrome(chrome_options=chrome_options) + if is_headless: + chrome_options.add_argument('--headless') + chrome_options.add_argument('--disable-gpu') + chrome_options.add_argument('log-level=2') + + driver = Chrome(options=chrome_options) driver.implicitly_wait(10) driver.get("https://facebook.com") email = "email" password = "pass" - login="loginbutton" + login = "loginbutton" emailelement = driver.find_element_by_name(email) - passwordelement = driver.find_element_by_name(password) emailelement.send_keys(user_email_address) - passwordelement.send_keys(user_password) loginelement = driver.find_element_by_id(login) - loginelement.click() + if "Two-factor authentication" in driver.page_source: # Allow time to enter 2FA code print("Pausing to enter 2FA code") @@ -106,3 +128,7 @@ def delete_posts(user_email_address=None, # Required to sleep the thread for a bit after using JS to click this button time.sleep(5) driver.refresh() + + +if __name__ == "__main__": + run_delete() -- 2.30.2