Guest User

Untitled

a guest
Mar 15th, 2019
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.96 KB | None | 0 0
  1. from selenium import webdriver
  2. from selenium.webdriver.common.keys import Keys
  3. from selenium.webdriver.support.ui import WebDriverWait
  4. from selenium.webdriver.firefox.options import Options
  5. from excel import Read_excel_data as Read_excel_data
  6. import time
  7. import random
  8.  
  9.  
  10. class facebook(Read_excel_data):
  11.     def __init__(self):
  12.         Read_excel_data.__init__(self)
  13.         self.options = webdriver.FirefoxOptions()
  14.         self.options = Options()
  15.         self.options.set_preference("dom.webnotifications.enabled", False)
  16.         self.driver = webdriver.Firefox(options=self.options)
  17.         self.login()
  18.         self.post_to_groups()
  19.  
  20.     def login(self):
  21.         self.driver.get("https://www.facebook.com/")
  22.         time.sleep(7)
  23.  
  24.         username = self.driver.find_element_by_xpath("//input[@name='email']").send_keys(self.username)
  25.  
  26.         password = self.driver.find_element_by_xpath("//input[@id='pass']").send_keys(self.password)
  27.         submit = self.driver.find_element_by_xpath("//input[@value='Log In']").click()
  28.         time.sleep(7)
  29.  
  30.     def post_to_groups(self):
  31.         color = self.color
  32.         color = color.strip(' ')
  33.         for group_link in self.group_list:
  34.             self.driver.get(group_link)
  35.             status = self.driver.find_element_by_xpath("//textarea[@name = 'xhpc_message_text']")
  36.             status.send_keys(self.post)
  37.             time.sleep(7)
  38.  
  39.             bg_image = self.driver.find_element_by_xpath("//i[@class = '_3ov1 img sp_E0oHonVlduq sx_990e59']").click()
  40.  
  41.             time.sleep(2)
  42.  
  43.             if(color == 'Black'):
  44.                 button_color_black = self.driver.find_element_by_xpath("//div[@class='uiContextualLayerPositioner _53ii uiLayer']//div[2]//table[1]//tbody[1]//tr[1]//td[1]")
  45.                 button_color_black.click()
  46.                 webdriver.ActionChains(self.driver).send_keys(Keys.ESCAPE).perform()
  47.                 time.sleep(2)
  48.  
  49.             elif(color == 'Red'):
  50.                 button_color_red = self.driver.find_element_by_xpath("//div[@class='uiContextualLayerPositioner _53ii uiLayer']//div[2]//table[1]//tbody[1]//tr[1]//td[3]")
  51.                 button_color_red.click()
  52.                 time.sleep(2)
  53.                 webdriver.ActionChains(self.driver).send_keys(Keys.ESCAPE).perform()
  54.                 time.sleep(2)
  55.  
  56.             elif(color == 'Blue'):
  57.                 button_color_blue = self.driver.find_element_by_xpath("//div[@class='uiContextualLayerPositioner _53ii uiLayer']//div[2]//table[1]//tbody[1]//tr[2]//td[6]")
  58.                 webdriver.ActionChains(self.driver).send_keys(Keys.ESCAPE).perform()
  59.                 button_color_blue.click()
  60.                 time.sleep(2)
  61.  
  62.             elif(color == 'None'):
  63.                 continue
  64.  
  65.             submit = self.driver.find_element_by_xpath("//div[@class='_332r']//button[@value='1']")
  66.             submit.click()
  67.  
  68.             time_to_sleep = random.randint(600, 900)
  69.             time.sleep(time_to_sleep)
  70.  
  71.  
  72. a = facebook()
Add Comment
Please, Sign In to add comment