Browse Source

Clean up

pull/51/head
Wesley Kerfoot 6 years ago
parent
commit
940a94afed
  1. 16
      deletefb/tools/common.py
  2. 9
      deletefb/tools/likes.py
  3. 8
      deletefb/tools/wall.py

16
deletefb/tools/common.py

@ -19,13 +19,15 @@ SELENIUM_EXCEPTIONS = (
TimeoutException TimeoutException
) )
def try_move(actions, el): def click_button(driver, el):
for _ in range(10): """
try: Click a button using Javascript
actions.move_to_element(el).perform() Args:
except StaleElementReferenceException: driver: seleniumrequests.Chrome Driver instance
time.sleep(5) Returns:
continue None
"""
driver.execute_script("arguments[0].click();", el)
def logger(name): def logger(name):
""" """

9
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.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC 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__) LOG = logger(__name__)
@ -70,15 +69,17 @@ def unlike_page(driver, url):
button = driver.find_element_by_xpath("//*[text()='Liked']") 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( wait.until(
EC.presence_of_element_located((By.XPATH, "//a/span[text()='Unlike']")) 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']/..") 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): def unlike_pages(driver, profile_url):

8
deletefb/tools/wall.py

@ -1,13 +1,11 @@
import time import time
from selenium.webdriver.common.action_chains import ActionChains 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 # Used as a threshold to avoid running forever
MAX_POSTS = 15000 MAX_POSTS = 15000
def delete_posts(driver, def delete_posts(driver,
user_profile_url, user_profile_url,
year=None): year=None):
@ -59,8 +57,8 @@ def delete_posts(driver,
actions.move_to_element(delete_button).click().perform() actions.move_to_element(delete_button).click().perform()
confirmation_button = driver.find_element_by_class_name("layerConfirm") confirmation_button = driver.find_element_by_class_name("layerConfirm")
# Facebook would not let me get focus on this button without some custom JS click_button(driver, confirmation_button)
driver.execute_script("arguments[0].click();", confirmation_button)
except SELENIUM_EXCEPTIONS: except SELENIUM_EXCEPTIONS:
continue continue
else: else:

Loading…
Cancel
Save