From 69313de81152ee5f20d0a1078cc6b2b6d83a31bb Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Sat, 1 Jun 2019 17:12:01 -0400 Subject: [PATCH 01/13] Refactor settings --- deletefb/config.py | 3 +++ deletefb/deletefb.py | 17 ++++++++--------- deletefb/tools/common.py | 7 +++++-- 3 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 deletefb/config.py diff --git a/deletefb/config.py b/deletefb/config.py new file mode 100644 index 0000000..16fb42a --- /dev/null +++ b/deletefb/config.py @@ -0,0 +1,3 @@ +settings = { + "ARCHIVE" : False +} diff --git a/deletefb/deletefb.py b/deletefb/deletefb.py index 54d0c66..c69d42b 100755 --- a/deletefb/deletefb.py +++ b/deletefb/deletefb.py @@ -6,6 +6,7 @@ import json import os import sys +from config import settings from tools.common import logger from tools.login import login from tools.wall import delete_posts @@ -13,7 +14,6 @@ from tools.likes import unlike_pages LOG = logger("deletefb") - def run_delete(): parser = argparse.ArgumentParser() @@ -92,11 +92,7 @@ def run_delete(): args = parser.parse_args() - if args.archive_off: - os.environ["DELETEFB_ARCHIVE"] = "false" - else: - os.environ["DELETEFB_ARCHIVE"] = "true" - + settings["ARCHIVE"] = not args.archive_off if args.year and args.mode != "wall": parser.error("The --year option is only supported in wall mode") @@ -111,9 +107,12 @@ def run_delete(): ) if args.mode == "wall": - delete_posts(driver, - args.profile_url, - year=args.year) + delete_posts( + driver, + args.profile_url, + year=args.year + ) + elif args.mode == "unlike_pages": unlike_pages(driver) else: diff --git a/deletefb/tools/common.py b/deletefb/tools/common.py index fe97881..e9b99af 100644 --- a/deletefb/tools/common.py +++ b/deletefb/tools/common.py @@ -2,9 +2,11 @@ import json import logging import logging.config import os -from os.path import abspath, relpath, split, isfile import time +from config import settings + +from os.path import abspath, relpath, split, isfile from selenium.common.exceptions import ( NoSuchElementException, StaleElementReferenceException, @@ -57,8 +59,9 @@ def archiver(category): log_file = open(log_path, mode="ta", buffering=1) def log(content, timestamp=False): - if os.environ.get("DELETEFB_ARCHIVE", "true") == "false": + if not settings["ARCHIVE"]: return + structured_content = { "category" : category, "content" : content, From e52dc89e07a5f0e1e03a209b5cac64f41d937ce6 Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Sat, 1 Jun 2019 17:20:17 -0400 Subject: [PATCH 02/13] Default should be 'True' for archive --- deletefb/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deletefb/config.py b/deletefb/config.py index 16fb42a..8ca2556 100644 --- a/deletefb/config.py +++ b/deletefb/config.py @@ -1,3 +1,3 @@ settings = { - "ARCHIVE" : False + "ARCHIVE" : True } From e8e9a3434f54fbcc2ee6b8bb4f4963c12374729f Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Sat, 1 Jun 2019 17:41:35 -0400 Subject: [PATCH 03/13] See if a driver.refresh() helps with unliking pages --- deletefb/tools/common.py | 1 - deletefb/tools/likes.py | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/deletefb/tools/common.py b/deletefb/tools/common.py index e9b99af..79815ec 100644 --- a/deletefb/tools/common.py +++ b/deletefb/tools/common.py @@ -13,7 +13,6 @@ from selenium.common.exceptions import ( TimeoutException ) - SELENIUM_EXCEPTIONS = ( NoSuchElementException, StaleElementReferenceException, diff --git a/deletefb/tools/likes.py b/deletefb/tools/likes.py index cbb8886..c332ba0 100644 --- a/deletefb/tools/likes.py +++ b/deletefb/tools/likes.py @@ -18,6 +18,8 @@ def load_likes(driver): Returns: None """ + + driver.refresh() driver.get("https://www.facebook.com/pages/?category=liked") wait = WebDriverWait(driver, 20) From 169321e9cc4c2931a8a427e0b8ca293d70ad2fb9 Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Sat, 1 Jun 2019 23:39:15 -0400 Subject: [PATCH 04/13] Refactor settings --- deletefb/deletefb.py | 1 + deletefb/tools/common.py | 2 +- deletefb/{ => tools}/config.py | 0 3 files changed, 2 insertions(+), 1 deletion(-) rename deletefb/{ => tools}/config.py (100%) diff --git a/deletefb/deletefb.py b/deletefb/deletefb.py index 0e4f546..484b5f9 100755 --- a/deletefb/deletefb.py +++ b/deletefb/deletefb.py @@ -6,6 +6,7 @@ import json import os import sys +from .tools.config import settings from .tools.common import logger from .tools.login import login from .tools.wall import delete_posts diff --git a/deletefb/tools/common.py b/deletefb/tools/common.py index 79815ec..06df691 100644 --- a/deletefb/tools/common.py +++ b/deletefb/tools/common.py @@ -4,7 +4,7 @@ import logging.config import os import time -from config import settings +from .config import settings from os.path import abspath, relpath, split, isfile from selenium.common.exceptions import ( diff --git a/deletefb/config.py b/deletefb/tools/config.py similarity index 100% rename from deletefb/config.py rename to deletefb/tools/config.py From 23ba502b657ef51b7f3c9de217f6a99096ac34ef Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Sun, 2 Jun 2019 01:59:41 -0400 Subject: [PATCH 05/13] Grab all URLs from page like page --- deletefb/deletefb.py | 2 +- deletefb/tools/likes.py | 48 +++++++++++------------------------------ 2 files changed, 13 insertions(+), 37 deletions(-) diff --git a/deletefb/deletefb.py b/deletefb/deletefb.py index 484b5f9..20db6e3 100755 --- a/deletefb/deletefb.py +++ b/deletefb/deletefb.py @@ -114,7 +114,7 @@ def run_delete(): ) elif args.mode == "unlike_pages": - unlike_pages(driver) + unlike_pages(driver, args.profile_url) else: print("Please enter a valid mode") sys.exit(1) diff --git a/deletefb/tools/likes.py b/deletefb/tools/likes.py index c332ba0..be86926 100644 --- a/deletefb/tools/likes.py +++ b/deletefb/tools/likes.py @@ -2,13 +2,14 @@ from selenium.webdriver.common.by import By from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC +from time import sleep from .common import SELENIUM_EXCEPTIONS, archiver, logger LOG = logger(__name__) -def load_likes(driver): +def load_likes(driver, profile_url): """ Loads the page that lists all pages you like @@ -19,24 +20,19 @@ def load_likes(driver): None """ - driver.refresh() - driver.get("https://www.facebook.com/pages/?category=liked") + driver.get("{0}/likes_all".format(profile_url)) wait = WebDriverWait(driver, 20) try: wait.until( - EC.presence_of_element_located((By.XPATH, "//button/div/div[text()='Liked']")) - ) - - wait.until( - EC.presence_of_element_located((By.XPATH, "//button/div/i[@aria-hidden=\"true\"]")) + EC.presence_of_element_located((By.CSS_SELECTOR, ".PageLikeButton")) ) except SELENIUM_EXCEPTIONS: LOG.exception("Traceback of load_likes") return -def unlike_pages(driver): +def unlike_pages(driver, profile_url): """ Unlike all pages @@ -49,40 +45,20 @@ def unlike_pages(driver): like_log, archive_likes = archiver("likes") + wait = WebDriverWait(driver, 20) actions = ActionChains(driver) - load_likes(driver) - - pages_list = driver.find_element_by_css_selector("#all_liked_pages") + load_likes(driver, profile_url) - actions.move_to_element(pages_list).perform() + pages = driver.find_elements_by_xpath("//li//div/div/a[contains(@class, 'lfloat')]") - unlike_buttons = pages_list.find_elements_by_xpath("//button/div/div[text()='Liked']/../..") - - while unlike_buttons: - for button in unlike_buttons: - try: - if "Liked" in button.text: - page_name = button.find_element_by_xpath("./../..").text.split("\n")[0] - - driver.execute_script("arguments[0].click();", button) - - archive_likes(page_name) + actions = ActionChains(driver) - print("{0} was unliked".format(page_name)) + page_urls = [page.get_attribute("href").replace("www", "mobile") for page in pages] - except SELENIUM_EXCEPTIONS: - continue + for url in page_urls: + driver.get(url) - load_likes(driver) - try: - pages_list = driver.find_element_by_css_selector("#all_liked_pages") - actions.move_to_element(pages_list).perform() - unlike_buttons = pages_list.find_elements_by_xpath("//button") - if not unlike_buttons: - break - except SELENIUM_EXCEPTIONS: - break # Explicitly close the log file when we're done with it like_log.close() From 2b1346720d5d32c5de50ee7c59cf56f2cc2b5b10 Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Sun, 2 Jun 2019 02:24:45 -0400 Subject: [PATCH 06/13] Refactor page links --- deletefb/tools/likes.py | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/deletefb/tools/likes.py b/deletefb/tools/likes.py index be86926..c1cb508 100644 --- a/deletefb/tools/likes.py +++ b/deletefb/tools/likes.py @@ -32,6 +32,24 @@ def load_likes(driver, profile_url): LOG.exception("Traceback of load_likes") return + +def get_page_links(driver): + pages = driver.find_elements_by_xpath("//li//div/div/a[contains(@class, 'lfloat')]") + + actions = ActionChains(driver) + + return [page.get_attribute("href").replace("www", "mobile") for page in pages] + + +def unlike_page(driver, url): + driver.get(url) + + actions = ActionChains(driver) + + button_element = find_element_by_xpath("//span[text()='Unlike']/..") + actions.move_to_element(button_element).click().perform() + + def unlike_pages(driver, profile_url): """ Unlike all pages @@ -45,20 +63,14 @@ def unlike_pages(driver, profile_url): like_log, archive_likes = archiver("likes") - wait = WebDriverWait(driver, 20) - actions = ActionChains(driver) - load_likes(driver, profile_url) - pages = driver.find_elements_by_xpath("//li//div/div/a[contains(@class, 'lfloat')]") - - actions = ActionChains(driver) - - page_urls = [page.get_attribute("href").replace("www", "mobile") for page in pages] - - for url in page_urls: - driver.get(url) + urls = get_page_links(driver) + while urls: + for url in urls: + print(unlike_page(driver, url)) + urls = get_page_links(driver) # Explicitly close the log file when we're done with it like_log.close() From 0d1e047aedd0f969a2ffe44bfc1994932f10d5c6 Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Sun, 2 Jun 2019 15:21:26 -0400 Subject: [PATCH 07/13] Page unliking working using mobile pages --- deletefb/tools/likes.py | 48 +++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/deletefb/tools/likes.py b/deletefb/tools/likes.py index c1cb508..1677979 100644 --- a/deletefb/tools/likes.py +++ b/deletefb/tools/likes.py @@ -8,7 +8,6 @@ from .common import SELENIUM_EXCEPTIONS, archiver, logger LOG = logger(__name__) - def load_likes(driver, profile_url): """ Loads the page that lists all pages you like @@ -22,7 +21,7 @@ def load_likes(driver, profile_url): driver.get("{0}/likes_all".format(profile_url)) - wait = WebDriverWait(driver, 20) + wait = WebDriverWait(driver, 30) try: wait.until( @@ -34,6 +33,14 @@ def load_likes(driver, profile_url): def get_page_links(driver): + """ + Gets all of the links to the pages you like + + Args: + driver: seleniumrequests.Chrome Driver instance + Returns: + List of URLs to pages + """ pages = driver.find_elements_by_xpath("//li//div/div/a[contains(@class, 'lfloat')]") actions = ActionChains(driver) @@ -42,12 +49,36 @@ def get_page_links(driver): def unlike_page(driver, url): + """ + Unlikes a page given the URL to it + Args: + driver: seleniumrequests.Chrome Driver instance + url: url string pointing to a page + + Returns: + None + + """ driver.get(url) + wait = WebDriverWait(driver, 30) actions = ActionChains(driver) - button_element = find_element_by_xpath("//span[text()='Unlike']/..") - actions.move_to_element(button_element).click().perform() + wait.until( + EC.presence_of_element_located((By.XPATH, "//*[text()='Liked']")) + ) + + button = driver.find_element_by_xpath("//*[text()='Liked']") + + driver.execute_script("arguments[0].click();", button) + + wait.until( + EC.presence_of_element_located((By.XPATH, "//a/span[text()='Unlike']")) + ) + + unlike_button = driver.find_element_by_xpath("//a/span[text()='Unlike']/..") + + driver.execute_script("arguments[0].click();", unlike_button) def unlike_pages(driver, profile_url): @@ -69,8 +100,13 @@ def unlike_pages(driver, profile_url): while urls: for url in urls: - print(unlike_page(driver, url)) - urls = get_page_links(driver) + unlike_page(driver, url) + load_likes(driver, profile_url) + try: + urls = get_page_links(driver) + except SELENIUM_EXCEPTIONS: + # We're done + break # Explicitly close the log file when we're done with it like_log.close() From 940a94afed1e7ae2de97bb8b06db551b521b0fe9 Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Sun, 2 Jun 2019 15:29:07 -0400 Subject: [PATCH 08/13] Clean up --- deletefb/tools/common.py | 16 +++++++++------- deletefb/tools/likes.py | 9 +++++---- deletefb/tools/wall.py | 8 +++----- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/deletefb/tools/common.py b/deletefb/tools/common.py index 06df691..cc9e95f 100644 --- a/deletefb/tools/common.py +++ b/deletefb/tools/common.py @@ -19,13 +19,15 @@ SELENIUM_EXCEPTIONS = ( TimeoutException ) -def try_move(actions, el): - for _ in range(10): - try: - actions.move_to_element(el).perform() - except StaleElementReferenceException: - time.sleep(5) - continue +def click_button(driver, el): + """ + Click a button using Javascript + Args: + driver: seleniumrequests.Chrome Driver instance + Returns: + None + """ + driver.execute_script("arguments[0].click();", el) def logger(name): """ diff --git a/deletefb/tools/likes.py b/deletefb/tools/likes.py index 1677979..9498f2e 100644 --- a/deletefb/tools/likes.py +++ b/deletefb/tools/likes.py @@ -2,9 +2,8 @@ from selenium.webdriver.common.by import By from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC -from time import sleep -from .common import SELENIUM_EXCEPTIONS, archiver, logger +from .common import SELENIUM_EXCEPTIONS, archiver, logger, click_button LOG = logger(__name__) @@ -70,15 +69,17 @@ def unlike_page(driver, url): button = driver.find_element_by_xpath("//*[text()='Liked']") - driver.execute_script("arguments[0].click();", button) + # Click the "Liked" button to open up "Unlike" + click_button(driver, button) wait.until( EC.presence_of_element_located((By.XPATH, "//a/span[text()='Unlike']")) ) + # There should be an "Unlike" button now, click it unlike_button = driver.find_element_by_xpath("//a/span[text()='Unlike']/..") - driver.execute_script("arguments[0].click();", unlike_button) + click_button(driver, unlike_button) def unlike_pages(driver, profile_url): diff --git a/deletefb/tools/wall.py b/deletefb/tools/wall.py index 9983e41..f164305 100644 --- a/deletefb/tools/wall.py +++ b/deletefb/tools/wall.py @@ -1,13 +1,11 @@ import time - from selenium.webdriver.common.action_chains import ActionChains -from .common import SELENIUM_EXCEPTIONS, archiver +from .common import SELENIUM_EXCEPTIONS, archiver, click_button # Used as a threshold to avoid running forever MAX_POSTS = 15000 - def delete_posts(driver, user_profile_url, year=None): @@ -59,8 +57,8 @@ def delete_posts(driver, actions.move_to_element(delete_button).click().perform() confirmation_button = driver.find_element_by_class_name("layerConfirm") - # Facebook would not let me get focus on this button without some custom JS - driver.execute_script("arguments[0].click();", confirmation_button) + click_button(driver, confirmation_button) + except SELENIUM_EXCEPTIONS: continue else: From bf6ce1d615deef413975f801212b68730e54a945 Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Sun, 2 Jun 2019 15:38:40 -0400 Subject: [PATCH 09/13] Match anything with "Unlike" for pages because FB keeps changing the elements --- deletefb/tools/likes.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/deletefb/tools/likes.py b/deletefb/tools/likes.py index 9498f2e..a245961 100644 --- a/deletefb/tools/likes.py +++ b/deletefb/tools/likes.py @@ -59,6 +59,7 @@ def unlike_page(driver, url): """ driver.get(url) + print(url) wait = WebDriverWait(driver, 30) actions = ActionChains(driver) @@ -73,11 +74,11 @@ def unlike_page(driver, url): click_button(driver, button) wait.until( - EC.presence_of_element_located((By.XPATH, "//a/span[text()='Unlike']")) + EC.presence_of_element_located((By.XPATH, "//*[text()='Unlike']")) ) # There should be an "Unlike" button now, click it - unlike_button = driver.find_element_by_xpath("//a/span[text()='Unlike']/..") + unlike_button = driver.find_element_by_xpath("//*[text()='Unlike']/..") click_button(driver, unlike_button) From 139801c37cf0dfc20b5a7c67d1554d84c4d99876 Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Sun, 2 Jun 2019 15:50:44 -0400 Subject: [PATCH 10/13] Update README --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eea8211..ddc4fc5 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,8 @@ git+https://github.com/weskerfoot/DeleteFB.git` ## Unlike Pages * You may use `-M unlike_pages` to unlike all of your pages. The names of the pages will be archived (unless archival is turned off), and this option - conflicts with the year option. + conflicts with the year option. This will only unlike your *pages* that you + have liked. It will *not* unlike anything else (like books or movies). ## Archival * The tool will archive everything being deleted by default in `.log` files. From 2580f4594e57b1e3eff7488537a7418f1e310198 Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Sun, 2 Jun 2019 16:26:13 -0400 Subject: [PATCH 11/13] Bump version and refactor to use bloom filters for avoiding dups --- deletefb/tools/common.py | 14 ++++++++++++++ deletefb/tools/config.py | 3 ++- deletefb/tools/likes.py | 14 ++++++++++---- deletefb/tools/wall.py | 3 ++- setup.py | 5 +++-- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/deletefb/tools/common.py b/deletefb/tools/common.py index cc9e95f..c107abf 100644 --- a/deletefb/tools/common.py +++ b/deletefb/tools/common.py @@ -6,6 +6,9 @@ import time from .config import settings +# Used to avoid duplicates in the log +from pybloom_live import BloomFilter + from os.path import abspath, relpath, split, isfile from selenium.common.exceptions import ( NoSuchElementException, @@ -59,10 +62,19 @@ def archiver(category): log_file = open(log_path, mode="ta", buffering=1) + bfilter = BloomFilter( + capacity=settings["MAX_POSTS"], + error_rate=0.001 + ) + def log(content, timestamp=False): if not settings["ARCHIVE"]: return + if content in bfilter: + # This was already archived + return + structured_content = { "category" : category, "content" : content, @@ -71,6 +83,8 @@ def archiver(category): log_file.write("{0}\n".format(json.dumps(structured_content))) + bfilter.add(content) + return (log_file, log) diff --git a/deletefb/tools/config.py b/deletefb/tools/config.py index 8ca2556..078efca 100644 --- a/deletefb/tools/config.py +++ b/deletefb/tools/config.py @@ -1,3 +1,4 @@ settings = { - "ARCHIVE" : True + "ARCHIVE" : True, + "MAX_POSTS" : 5000 } diff --git a/deletefb/tools/likes.py b/deletefb/tools/likes.py index a245961..3adb151 100644 --- a/deletefb/tools/likes.py +++ b/deletefb/tools/likes.py @@ -47,19 +47,23 @@ def get_page_links(driver): return [page.get_attribute("href").replace("www", "mobile") for page in pages] -def unlike_page(driver, url): +def unlike_page(driver, url, archive=None): """ Unlikes a page given the URL to it Args: driver: seleniumrequests.Chrome Driver instance url: url string pointing to a page + archive: archiver instance Returns: None """ + driver.get(url) - print(url) + + print("Unliking {0}".format(url)) + wait = WebDriverWait(driver, 30) actions = ActionChains(driver) @@ -82,6 +86,8 @@ def unlike_page(driver, url): click_button(driver, unlike_button) + if archive: + archive(url) def unlike_pages(driver, profile_url): """ @@ -102,9 +108,9 @@ def unlike_pages(driver, profile_url): while urls: for url in urls: - unlike_page(driver, url) - load_likes(driver, profile_url) + unlike_page(driver, url, archive=archive_likes) try: + load_likes(driver, profile_url) urls = get_page_links(driver) except SELENIUM_EXCEPTIONS: # We're done diff --git a/deletefb/tools/wall.py b/deletefb/tools/wall.py index f164305..5dcd6ec 100644 --- a/deletefb/tools/wall.py +++ b/deletefb/tools/wall.py @@ -1,10 +1,11 @@ import time from selenium.webdriver.common.action_chains import ActionChains +from .config import settings from .common import SELENIUM_EXCEPTIONS, archiver, click_button # Used as a threshold to avoid running forever -MAX_POSTS = 15000 +MAX_POSTS = settings["MAX_POSTS"] def delete_posts(driver, user_profile_url, diff --git a/setup.py b/setup.py index 7e3f445..ce75ca6 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open("README.md", "r") as fh: setuptools.setup( name="delete-facebook-posts", - version="1.1.1", + version="1.1.2", author="Wesley Kerfoot", author_email="wes@wesk.tech", description="A Selenium Script to Delete Facebook Posts", @@ -16,7 +16,8 @@ setuptools.setup( install_requires = [ "selenium", "selenium-requests", - "requests" + "requests", + "pybloom-live" ], classifiers= [ "Programming Language :: Python :: 3", From 5cc653b2d5ebded2e4ac4d2f818eb39020def776 Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Sun, 2 Jun 2019 16:30:18 -0400 Subject: [PATCH 12/13] Use single quotes in the README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ddc4fc5..5263b14 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ git+https://github.com/weskerfoot/DeleteFB.git` brew cask install chromedriver ``` -* Run `deletefb -E "youremail@example.org" -P "yourfacebookpassword" -U "https://www.facebook.com/your.profile.url"` +* Run `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 start deleting posts. If it cannot delete something, then it will "hide" it from your timeline instead. From f4b015b95f0fb1bf55b6451dae0087fdc4aece23 Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Sun, 2 Jun 2019 16:42:20 -0400 Subject: [PATCH 13/13] Try to move elegantly handle broken pages --- deletefb/tools/likes.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/deletefb/tools/likes.py b/deletefb/tools/likes.py index 3adb151..9533eaa 100644 --- a/deletefb/tools/likes.py +++ b/deletefb/tools/likes.py @@ -64,13 +64,17 @@ def unlike_page(driver, url, archive=None): print("Unliking {0}".format(url)) - wait = WebDriverWait(driver, 30) + wait = WebDriverWait(driver, 60) actions = ActionChains(driver) - wait.until( - EC.presence_of_element_located((By.XPATH, "//*[text()='Liked']")) - ) + try: + wait.until( + EC.presence_of_element_located((By.XPATH, "//*[text()='Liked']")) + ) + except SELENIUM_EXCEPTIONS: + # Something went wrong with this page, so skip it + return button = driver.find_element_by_xpath("//*[text()='Liked']")