This repository has been archived by the owner on Jul 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
FBEraser.py
executable file
·147 lines (133 loc) · 5.15 KB
/
FBEraser.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env python
from __future__ import print_function
from selenium import webdriver
from bs4 import BeautifulSoup
from argparse import ArgumentParser
from time import sleep
import getpass
import sys
if sys.version[0] == '3': raw_input=input # for python 2/3 cross compatibility
class Eraser(object):
"""
Eraser class to remove Facebook content
Set up, log in, go to activity page, then repeat delete
If having trouble, use scroll down method or increase wait time
Don't forget to quit in the end
"""
def __init__(self, email, password, wait=1):
"""
Set up the eraser
:return: Null
"""
self.driver = webdriver.Firefox()
self.email = email
self.password = password
self.profile_name = None # this will end up being the facebook user name
self.count = 0 # counter of number of elements deleted
self.wait = wait
def quit(self):
"""
Quit the program (close out the browser)
:return: Null
"""
self.driver.quit()
def login(self):
"""
Log in to Facebook, set profile name
:return: Null
"""
self.driver.get('https://www.facebook.com/login/')
email_element = self.driver.find_element_by_id('email')
email_element.send_keys(self.email)
password_element = self.driver.find_element_by_id('pass')
password_element.send_keys(self.password)
password_element.submit()
soup = BeautifulSoup(self.driver.page_source)
profile_link = soup.find('a', {'title': 'Profile'})
self.profile_name = profile_link.get('href')[25:] # link appears as http://www.facebook.com/PROFILE
def go_to_activity_page(self):
"""
Go to the activity page and prepare to start deleting
:return: Null
"""
if not self.profile_name:
# the user hasn't logged in properly
sys.exit(-2)
# go to the activity page (filter by 'Your Posts')
activity_link = 'https://www.facebook.com/' + self.profile_name + '/allactivity?privacy_source=activity_log&log_filter=cluster_11'
self.driver.get(activity_link)
sleep(self.wait)
def scroll_down(self):
"""
Executes JS to scroll down on page.
Use if having trouble seeing elements
:return:
"""
self.driver.execute_script('window.scrollTo(0, document.body.scrollHeight);')
sleep(self.wait)
def delete_element(self):
"""
Find the first available element and delete it
:return: Null
"""
# click hidden from timeline so the delete button shows up
soup = BeautifulSoup(self.driver.page_source)
# Priority: highlights, allowed, hidden
menu_button = soup.find('a', {'aria-label': 'Highlighted on Timeline'})
if menu_button is None:
menu_button = soup.find('a', {'aria-label': 'Allowed on Timeline'})
if menu_button is None:
menu_button = soup.find('a', {'aria-label': 'Hidden from Timeline'})
if menu_button is None:
menu_button = soup.find('a', {'aria-label': 'Shown on Timeline'})
menu_element = self.driver.find_element_by_id(menu_button.get('id'))
menu_element.click()
sleep(self.wait)
# now that the delete button comes up, find the delete link and click
# sometimes it takes more than one click to get the delete button to pop up
if menu_button is not None:
i = 0
while i < 3:
try:
self.driver.find_element_by_link_text('Delete').click()
break
except:
print ('[*] Clicking menu again')
menu_element.click()
i += 1
sleep(self.wait)
# click the confirm button, increment counter and display success
self.driver.find_element_by_class_name('layerConfirm').click()
self.count += 1
print ('[+] Element Deleted ({count} in total)'.format(count=self.count))
sleep(self.wait)
if __name__ == '__main__':
"""
Main section of script
"""
# set up the command line argument parser
parser = ArgumentParser(description='Delete your Facebook activity. Requires Firefox')
parser.add_argument('--wait', type=float, default=1, help='Explicit wait time between page loads (default 1 second)')
args = parser.parse_args()
# execute the script
email = raw_input("Please enter Facebook login email: ")
password = getpass.getpass()
eraser = Eraser(email=email, password=password, wait=args.wait)
eraser.login()
eraser.go_to_activity_page()
# track failures
fail_count = 0
while True:
if fail_count >= 3:
print ('[*] Scrolling down')
eraser.scroll_down()
fail_count = 0
sleep(5)
try:
print ('[*] Trying to delete element')
eraser.delete_element()
fail_count = 0
except (Exception, ) as e:
print ('[-] Problem finding element')
fail_count += 1
sleep(2)