Skip to content

Commit

Permalink
Several imprevements, more error handling and fix in "postToTimeline"…
Browse files Browse the repository at this point in the history
… method
  • Loading branch information
hikaruAi committed Jan 31, 2016
1 parent 1a96dea commit fc9994b
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions FacebookWebBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def postTextToTimeline(self, text, screenshot=True, screenshotPath="\\"):
textbox = self.find_element_by_name("xc_message")
textbox.send_keys(text)
submit = self.find_element_by_name("view_post")
submit.click()
return self.getScrenshotName("Post_", screenshot, screenshotPath)


Expand Down Expand Up @@ -173,7 +174,7 @@ def getPostInGroup(self, url, deep=2, screenshot=True, screenshotPath="\\"):
posts = []
for n in range(deep):
for i in ids:
print(i)
#print(i)
post = Post()
try:
p = self.find_element_by_id("u_0_" + str(i))
Expand Down Expand Up @@ -205,9 +206,10 @@ def getPostInGroup(self, url, deep=2, screenshot=True, screenshotPath="\\"):
more = self.find_element_by_class_name("dm").find_elements_by_tag_name("a")[0].get_attribute('href')
self.get(more)
except Exception:
print("can't get more :(")
return posts, self.getScrenshotName("PostsIn" + self.title, screenshot, screenshotPath)

pass
#print("can't get more :(")
#return posts, self.getScrenshotName("PostsIn" + self.title, screenshot, screenshotPath)
return posts

def postInGroup(self, groupURL, text, screenshot=False, screenshotPath="\\"):
self.get(groupURL)
Expand Down Expand Up @@ -244,12 +246,14 @@ def postImageInGroup(self, url, text, image1, image2="", image3=""):
return True

def commentInPost(self, postUrl, text, screenshot=True, screenshotPath="\\"):
self.get(postUrl)
tb = self.find_element_by_name("comment_text")
tb.send_keys(text)
tb.send_keys(Keys.ENTER)
return self.getScrenshotName("CommentingIn_" + self.title, screenshot, screenshotPath)

try:
self.get(postUrl)
tb = self.find_element_by_name("comment_text")
tb.send_keys(text)
tb.send_keys(Keys.ENTER)
return self.getScrenshotName("CommentingIn_" + self.title, screenshot, screenshotPath)
except Exception as e:
print("Can't comment in ",postUrl,"\n->",e)
def getGroupMembers(self, url, deep=3, start=0):
seeMembersUrl = url + "?view=members&refid=18"
groupId = url.split("groups/")[1]
Expand Down Expand Up @@ -320,8 +324,11 @@ def getGroups(self):
except ValueError:
group_name = b.text
notis = 0
link = b.find_element_by_tag_name("a").get_attribute('href')
g[group_name] = (mfacebookToBasic(link), notis)
try:
link = b.find_element_by_tag_name("a").get_attribute('href')
g[group_name] = (mfacebookToBasic(link), notis)
except Exception as e:
print("Can't get group link")
return g

def getSuggestedGroups(self, sendrequest=False):
Expand All @@ -345,4 +352,4 @@ def getSuggestedGroups(self, sendrequest=False):
print("Request to group: ", r)
except Exception:
print("Fail to send request to: ", r)
return g
return g

0 comments on commit fc9994b

Please sign in to comment.