-
Notifications
You must be signed in to change notification settings - Fork 12
/
run.py
77 lines (63 loc) · 2.11 KB
/
run.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
from datetime import datetime
from time import sleep
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
username = input('Enter your username: ')
password = input('Enter your password: ')
number_time_post = int(input('Enter the number times post: '))
id_target = int(input('Enter the target ID (page, group, user): '))
content = input('Enter the content of the posts: ')
chrome_options = Options()
chrome_options.add_experimental_option(
"prefs", {'profile.managed_default_content_settings.javascript': 2}
)
driver = webdriver.Chrome('chromedriver', chrome_options=chrome_options)
driver.get("https://m.facebook.com/")
print("Opened facebook")
username_box = driver.find_element_by_id('m_login_email')
username_box.send_keys(username)
print("Email Id entered")
password_box = driver.find_element_by_id('m_login_password')
password_box.send_keys(password)
print("Password entered")
login_box = driver.find_element_by_id('u_0_5')
sleep(1)
login_box.click()
try:
if driver.find_element_by_id('m_login_email') or \
driver.find_element_by_id('m_login_password'):
print("The username or password is incorrect")
exit(1)
except Exception:
pass
count = 0
print('Index\t Duration')
start_process = datetime.now()
while number_time_post > 0:
start = datetime.now()
count += 1
driver.get(
"https://m.facebook.com/{}".format(id_target)
)
message_box = None
try:
message_box = driver.find_element_by_name('xc_message')
except Exception:
message_box = driver.find_element_by_id('u_0_0')
finally:
if not message_box:
print('Something went wrong. Please check it again')
exit(1)
message_box.send_keys(
content + ' \n.\n.\n.\n.\n.\n' + str(datetime.now().timestamp())
)
post_btn = driver.find_element_by_name('view_post')
sleep(1)
post_btn.click()
end = datetime.now()
duration = end - start
print("{}\t {}".format(count, duration))
number_time_post -= 1
end_process = datetime.now()
print('Total\t {}'.format(end_process - start_process))
driver.close()