-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathFacebook Spammer.py
82 lines (67 loc) · 3.98 KB
/
Facebook Spammer.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
import time
import pyperclip
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# ------------------ USER INPUT ------------------ #
email_id = ''
password = ''
page_link = ''
number_of_times =
frequency =
message = ""
# ----------------- INITIALIZE CHROMEDRIVER ---------------------- #
capa = DesiredCapabilities.CHROME
capa["pageLoadStrategy"] = "none" # Enable explicit wait.
options = webdriver.ChromeOptions()
options.add_argument('--start-maximized') # Start Chrome maximized.
options.add_argument('--disable-notifications')
url = 'https://www.facebook.com'
driver = webdriver.Chrome('E:\Python\chromedriver.exe', desired_capabilities=capa, chrome_options=options) # Arguments
driver.get(url)
# ---------------- LOG IN AND SPAM ----------------- #
WebDriverWait(driver, 150).until(EC.presence_of_element_located((By.ID, "email")))
driver.find_element_by_id('email').send_keys(email_id) # Enter Email ID
driver.find_element_by_id('pass').send_keys(password) # Enter password
driver.find_element_by_xpath("//input[@value='Log In']").click() # Login
WebDriverWait(driver, 150).until(EC.presence_of_element_located((By.XPATH, "//input[@placeholder='Search']")))
driver.get(page_link) # Go to page or profile
time.sleep(10)
''' Keep scrolling down until the number of spammable posts >= number_of_times'''
comment_boxes = driver.find_elements_by_xpath("//div[text()='Write a comment...']")
while len(comment_boxes) < number_of_times:
try:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
except:
pass
comment_boxes = driver.find_elements_by_xpath("//div[text()='Write a comment...']")
driver.execute_script("window.scrollTo(document.body.scrollHeight, 0);") # Go to top of page.
time.sleep(5)
original = len(driver.find_elements_by_xpath("//div[text()='Write a comment...']")) # Keep track of number of posts.
pyperclip.copy(message) # Copy the message to clipboard.
actions = ActionChains(driver) # Initialize ActionChains
actions.key_down(Keys.CONTROL).send_keys('v').key_up(Keys.CONTROL).send_keys(Keys.ENTER) # Ctrl+V
for i in range(0, number_of_times):
for j in range(0, frequency):
comment_boxes = driver.find_elements_by_xpath("//div[text()='Write a comment...']") # Find the comment boxes.
driver.execute_script("arguments[0].scrollIntoView({block: 'center'})", comment_boxes[i]) # Scroll to view.
time.sleep(2)
driver.execute_script("arguments[0].click();", comment_boxes[i]) # Click on comment box.
check = True
while check is True:
try:
comment_boxes = driver.find_elements_by_xpath("//div[text()='Write a comment...']")
if comment_boxes[i].find_element_by_xpath('..').value_of_css_property('color') == \
'rgba(190, 195, 201, 1)':
check = False
except:
pass
actions.perform() # Perform Ctrl+V
''' Perform next comment only when previous comment is performed.'''
while len(driver.find_elements_by_xpath("//div[text()='Write a comment...']")) < original:
time.sleep(0.5)
print(str(i+1), "/", str(number_of_times), "posts spammed.")