|
@ -1,10 +1,28 @@ |
|
|
from time import sleep |
|
|
|
|
|
from selenium.webdriver.common.by import By |
|
|
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 .common import SELENIUM_EXCEPTIONS, archiver |
|
|
from .common import SELENIUM_EXCEPTIONS, archiver |
|
|
|
|
|
|
|
|
|
|
|
def load_likes(driver): |
|
|
|
|
|
""" |
|
|
|
|
|
Loads the page that lists all pages you like |
|
|
|
|
|
""" |
|
|
|
|
|
driver.get("https://www.facebook.com/pages/?category=liked") |
|
|
|
|
|
|
|
|
|
|
|
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\"]")) |
|
|
|
|
|
) |
|
|
|
|
|
except SELENIUM_EXCEPTIONS: |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
def unlike_pages(driver, |
|
|
def unlike_pages(driver, |
|
|
user_profile_url): |
|
|
user_profile_url): |
|
|
""" |
|
|
""" |
|
@ -15,30 +33,40 @@ def unlike_pages(driver, |
|
|
|
|
|
|
|
|
actions = ActionChains(driver) |
|
|
actions = ActionChains(driver) |
|
|
|
|
|
|
|
|
driver.get("https://www.facebook.com/pages/?category=liked") |
|
|
load_likes(driver) |
|
|
|
|
|
|
|
|
wait = WebDriverWait(driver, 20) |
|
|
|
|
|
|
|
|
|
|
|
wait.until( |
|
|
|
|
|
EC.presence_of_element_located((By.XPATH, "//div[text()='Liked']")) |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
sleep(10) |
|
|
|
|
|
|
|
|
|
|
|
pages_list = driver.find_element_by_css_selector("#all_liked_pages") |
|
|
pages_list = driver.find_element_by_css_selector("#all_liked_pages") |
|
|
|
|
|
|
|
|
actions.move_to_element(pages_list).perform() |
|
|
actions.move_to_element(pages_list).perform() |
|
|
unlike_buttons = pages_list.find_elements_by_xpath("//button") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unlike_buttons = pages_list.find_elements_by_xpath("//button/div/div[text()='Liked']/../..") |
|
|
|
|
|
|
|
|
|
|
|
while unlike_buttons: |
|
|
for button in unlike_buttons: |
|
|
for button in unlike_buttons: |
|
|
try: |
|
|
try: |
|
|
actions.move_to_element(button).perform() |
|
|
if "Liked" in button.text: |
|
|
page_name = button.find_element_by_xpath("./../..").text.split("\n")[0] |
|
|
page_name = button.find_element_by_xpath("./../..").text.split("\n")[0] |
|
|
|
|
|
|
|
|
|
|
|
print("Trying to unlike {0}".format(page_name)) |
|
|
|
|
|
|
|
|
|
|
|
driver.execute_script("arguments[0].click();", button) |
|
|
|
|
|
|
|
|
archive_likes(page_name) |
|
|
archive_likes(page_name) |
|
|
|
|
|
|
|
|
|
|
|
print("{0} was unliked".format(page_name)) |
|
|
|
|
|
|
|
|
except SELENIUM_EXCEPTIONS as e: |
|
|
except SELENIUM_EXCEPTIONS as e: |
|
|
print(e) |
|
|
|
|
|
continue |
|
|
continue |
|
|
print(button) |
|
|
|
|
|
|
|
|
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 |
|
|
# Explicitly close the log file when we're done with it |
|
|
like_log.close() |
|
|
like_log.close() |
|
|