Created
April 5, 2025 16:38
-
-
Save misopog/1c8b5ca629bd99e5406a2930a504e7ee to your computer and use it in GitHub Desktop.
facebook mass unfollower
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse, time | |
from selenium import webdriver | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions as EC | |
parser = argparse.ArgumentParser() | |
parser.add_argument('email') | |
parser.add_argument('password') | |
args = parser.parse_args() | |
print("starting...") | |
options = webdriver.ChromeOptions() | |
driver = webdriver.Chrome(options=options) | |
try: | |
print("logging in...") | |
driver.get("https://www.facebook.com/login.php") | |
time.sleep(2) | |
email_field = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, "email"))) | |
email_field.send_keys(args.email) | |
password_field = driver.find_element(By.ID, "pass") | |
password_field.send_keys(args.password) | |
login_button = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "login"))) | |
driver.execute_script("arguments[0].click();", login_button) | |
while driver.current_url != "https://www.facebook.com/": | |
time.sleep(1) | |
print("going to liked pages") | |
driver.get("https://www.facebook.com/pages/?category=liked&ref=bookmarks") | |
time.sleep(2) | |
unfollowed = 0 | |
refreshes = 0 | |
while refreshes < 5: | |
following_spans = driver.find_elements(By.XPATH, "//span[contains(text(), 'Following')]") | |
if not following_spans: | |
print("no more pages found, refreshing") | |
driver.refresh() | |
refreshes += 1 | |
time.sleep(2) | |
continue | |
for span in following_spans: | |
try: | |
parent_div = span.find_element(By.XPATH, "./ancestor::div[contains(@role, 'button')]") | |
driver.execute_script("arguments[0].click();", parent_div) | |
unfollowed += 1 | |
time.sleep(1) | |
except Exception as e: | |
print(f"failed to unfollow: {e}") | |
continue | |
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") | |
time.sleep(1) | |
except Exception as e: | |
print(f"error occurred: {e}") | |
finally: | |
print(f"total pages unfollowed: {unfollowed}") | |
driver.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment