-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFBBotSelenium.py
More file actions
106 lines (72 loc) · 2.76 KB
/
FBBotSelenium.py
File metadata and controls
106 lines (72 loc) · 2.76 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
import selenium
import os
from selenium.webdriver.common.keys import Keys
import time
import json
class FBBot():
def __init__(self, email, password):
self.browser = selenium.webdriver.Chrome("chromedriver")
self.email = email
self.password = password
def login(self):
self.browser.get('https://mbasic.facebook.com')
# two input fields
emailField = self.browser.find_element_by_name('email')
passwordField = self.browser.find_element_by_name('pass')
emailField.send_keys(self.email)
passwordField.send_keys(self.password)
# get login button
loginButton = self.browser.find_element_by_name('login')
# click login button
loginButton.click()
time.sleep(2)
def likePage(self, pageURL):
self.browser.get(pageURL)
# get like reference link
likeButton = self.browser.find_element_by_xpath('//*[@id="sub_profile_pic_content"]/div/div[2]/table/tbody/tr/td[1]/a')
refLink = likeButton.get_attribute('href')
# debug
# print(refLink)
if refLink.startswith('https://mbasic.facebook.com/a/profile.php?fan&'):
print("Liking the page.")
else:
print("Unliking the page.")
# execute it to like/unlike it
self.browser.get(refLink)
def followPage(self, pageURL):
self.browser.get(pageURL)
followButton = self.browser.find_element_by_xpath('//*[@id="pages_follow_action_id"]')
refLink = followButton.get_attribute('href')
# debug
#print(refLink)
if refLink.startswith('https://mbasic.facebook.com/a/subscriptions/add'):
print('Following the page.')
else:
print('Unfollowing the page.')
# execute it to follow/unfollow it
self.browser.get(refLink)
def postStatusToFeed(self, message):
self.browser.get('https://mbasic.facebook.com/home.php')
# post message input
statusInput = self.browser.find_element_by_name('xc_message')
statusInput.send_keys(message)
# Post button
postButton = self.browser.find_element_by_name('view_post')
postButton.click()
def get_credentials():
with open('credentials.json') as json_file:
data = json.load(json_file)
return data
return
def main():
# get credentials from json
user_infos = get_credentials()
# initialize login process with given infos
bot = FBBot(user_infos['email'], user_infos['password'])
bot.login()
bot.likePage('https://mbasic.facebook.com/tharngeIV/')
bot.followPage('https://mbasic.facebook.com/ncybersec')
bot.postStatusToFeed('testttt')
return
if __name__ == "__main__":
main()