-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfacebook.py
More file actions
153 lines (134 loc) · 5.49 KB
/
facebook.py
File metadata and controls
153 lines (134 loc) · 5.49 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
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
148
149
150
151
152
153
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
import random
class FacebookAdder:
def __init__(self):
self.chrome_options = webdriver.ChromeOptions()
self.prefs = {"profile.managed_default_content_settings.images": 2,
"profile.managed_default_content_settings.notifications": 2, "profile.managed_default_content_settings.popups": 2}
def run_normal(self):
self.chrome_options.add_experimental_option(
"prefs", {self.prefs[1], self.prefs[2]})
self.driver = webdriver.Chrome(
r"C:\\webdrivers\\chromedriver.exe", chrome_options=self.chrome_options)
def run_in_image_off_mode(self):
self.chrome_options.add_experimental_option("prefs", self.prefs)
self.driver = webdriver.Chrome(
r"C:\\webdrivers\\chromedriver.exe", chrome_options=self.chrome_options)
def login(self, gmail, password):
self.driver.get("https://facebook.com")
while True:
try:
self.driver.find_element_by_xpath("""//*[@id="email"]""")\
.send_keys(gmail)
self.driver.find_element_by_xpath("""//*[@id="pass"]""")\
.send_keys(password)
self.driver.find_element_by_xpath("""//*[@id = "u_0_b"]""")\
.click()
break
except:
sleep(3)
def click_friends(self):
sleep(1)
while True:
try:
self.driver.get("https://www.facebook.com/?sk=ff")
break
except:
pass
def clicking_add_friend(self):
count = 0
while True:
print("Im at first")
try:
while True:
print("Im at while true")
list_of_buttons = self.driver.find_elements_by_class_name(
"selected")
for buttons in list_of_buttons:
try:
buttons.click()
count = 0
print(count)
random_time = random.randint(800, 1000)/1000
sleep(random_time)
except:
count += 1
print("Im at buttons except")
sleep(random.randint(5000, 10000)/1000)
except:
print("Im at facebook.com/?sk=ff")
count += 1
print(count)
if count > 10:
self.driver.get(
"https://www.facebook.com/?sk=ff")
count = 0
sleep(3)
def add_friend(self):
print("I'm in add_friend")
while True:
try:
while True:
list_of_buttons = self.driver.find_elements_xpa(
"FriendRequestAdd")
for buttons in list_of_buttons:
try:
buttons.click()
random_time = random.randint(800, 1000)/1000
sleep(random_time)
except:
pass
sleep(random.randint(5000, 10000)/1000)
except:
sleep(1)
self.driver.find_element_by_class_name("layerConfirm").click()
else:
sleep(3)
webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform()
finally:
pass
def delete_requests(self):
sleep(3)
count=0
self.driver.get(
"https://www.facebook.com/friends/requests/?fcref=jwl&outgoing=1#")
while True:
print("Im at first")
try:
while True:
print("Im at while true")
list_of_buttons = self.driver.find_elements_by_class_name(
"outgoingButton")
for buttons in list_of_buttons:
try:
buttons.click()
count = 0
print(count)
random_time = random.randint(800, 1000)/1000
sleep(random_time)
except:
self.driver.find_element_by_xpath(
"""//*[@id="outgoing_reqs_pager_5ef4a85b1ad525d68180008"]/div/a""").click()
print("Im at buttons except")
sleep(3)
except:
self.driver.find_element_by_xpath(
"""//*[@id="outgoing_reqs_pager_5ef4a85b1ad525d68180008"]/div/a""").click()
sleep(3)
else:
print("Im at facebook.com/?sk=ff")
count += 1
print(count)
if count > 10:
self.driver.get(
"https://www.facebook.com/?sk=ff")
count = 0
sleep(3)
if __name__ == "__main__":
testing = FacebookAdder()
testing.run_in_image_off_mode()
testing.login(gmail='gmail', password='password')
testing.add_friend()
# testing.add_friend()