-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
89 lines (71 loc) · 2.97 KB
/
main.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
import time
from DrissionPage import ChromiumPage, ChromiumOptions
class FacebookBot:
def __init__(self):
self.encode = 'utf-8'
self.driver = None
def read_from_file(self, path):
try:
with open(path, "r", encoding=self.encode) as file:
return file.read()
except Exception as e:
print(f'read_from_file exception: {str(e)}')
def write_to_file(self, path, content):
try:
with open(path, "a", encoding=self.encode) as file:
txt = self.read_from_file(path)
if content not in txt:
file.write(f"{content}\n")
except Exception as e:
print(f'write_to_file exception: {str(e)}')
def setup_chromium(self):
try:
options = ChromiumOptions()
options.set_paths('/usr/bin/google-chrome')
arguments = [
"-no-first-run",
"-force-color-profile=srgb",
"-metrics-recording-only",
"-password-store=basic",
"-use-mock-keychain",
"-export-tagged-pdf",
"-no-default-browser-check",
"-disable-background-mode",
"-enable-features=NetworkService,NetworkServiceInProcess,LoadCryptoTokenExtension,PermuteTLSExtensions",
"-disable-features=FlashDeprecationWarning,EnablePasswordsAccountStorage",
"-deny-permission-prompts",
"-disable-gpu",
"--incognito"
]
for argument in arguments:
options.set_argument(argument)
self.driver = ChromiumPage(options)
return self.driver
except Exception as e:
print(f'setup_chromium exception: {str(e)}')
def process_account(self, acc):
try:
username, password = acc.split(":")
self.driver.get('https://www.facebook.com')
login_input = self.driver.ele('xpath://*[@id="email"]')
password_input = self.driver.ele('xpath://*[@id="pass"]')
submit_button = self.driver.ele('xpath://*[@name="login"]')
login_input.input(username)
password_input.input(password)
submit_button.click()
time.sleep(5)
if "https://www.facebook.com/" == self.driver.url:
self.write_to_file('/path/to/work_accounts.txt', acc)
print(f"work -> {acc}")
self.driver.close()
except Exception as e:
print(f'process_account exception: {str(e)}')
def run(self):
accounts_list = self.read_from_file('/path/to/accounts.txt')
if accounts_list:
for account in accounts_list.split('\n'):
self.setup_chromium()
self.process_account(account)
if __name__ == '__main__':
bot = FacebookBot()
bot.run()