-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfb.py
More file actions
51 lines (45 loc) · 1.48 KB
/
fb.py
File metadata and controls
51 lines (45 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
# Fill in your credentials here
FB_EMAIL = "[email protected]"
FB_PASS = "Rev0luti0n2o2o"
driver = webdriver.Chrome()
driver.get("https://www.facebook.com/login")
time.sleep(3)
# Login
driver.find_element(By.ID, "email").send_keys(FB_EMAIL)
driver.find_element(By.ID, "pass").send_keys(FB_PASS)
driver.find_element(By.NAME, "login").click()
time.sleep(7) # Give time for login
# Go to friends page
driver.get("https://www.facebook.com/me/friends")
time.sleep(8) # Wait for page to load
# Scroll to load more friends
for i in range(8):
try:
driver.find_element(By.TAG_NAME, 'body').send_keys(Keys.END)
time.sleep(3)
except Exception as e:
print("Error during scrolling:", e)
# Find all "Friends" buttons and attempt to unfriend
buttons = driver.find_elements(By.XPATH, "//div[@aria-label='Friends']")
print(f"Found {len(buttons)} friend buttons.")
for btn in buttons:
try:
btn.click()
time.sleep(1)
# Try different possible XPaths for "Unfriend"
try:
unfriend = driver.find_element(By.XPATH, "//span[text()='Unfriend']")
unfriend.click()
print("Unfriended one.")
except:
print("Unfriend button not found after click.")
time.sleep(2)
except Exception as e:
print("Error:", e)
continue
# Only quit at the very end
driver.quit()