friend_request.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from selenium import webdriver
  2. from selenium.webdriver.common.by import By
  3. import time
  4. import configparser
  5. import sys
  6. def restart_browser(userdatadir):
  7. options = webdriver.ChromeOptions()
  8. options.add_argument("start-maximized")
  9. # options.add_argument('user-data-dir=C:/Users/XXXXXXXXX/AppData/Local/Google/Chrome/User Data/') # replace XXXXXXXXX with your own username
  10. options.add_argument('user-data-dir='+userdatadir) # replace XXXXXXXXX with your own username
  11. options.add_argument('--profile-directory="Default"')
  12. driver=webdriver.Chrome(chrome_options=options)
  13. driver.set_window_size(1400,1000)
  14. return driver
  15. config = configparser.ConfigParser()
  16. #config.sections()
  17. config.read('c:/portable/choozmo.ini')
  18. userdatadir=config['DEFAULT']['userdatadir']
  19. #for k,v in config['DEFAULT'].items():
  20. # print(k)
  21. #sys.exit()
  22. driver=restart_browser(userdatadir)
  23. driver.get('https://www.facebook.com/friends/requests')
  24. #friend request confirm
  25. reqs = driver.find_elements(By.XPATH, "//*[contains(@class,'l9j0dhe7 du4w35lb j83agx80 pfnyh3mw taijpn5t bp9cbjyn owycx6da btwxx1t3 kt9q3ron ak7q8e6j isp2s0ed ri5dt5u2 rt8b4zig n8ej3o3l agehan2d sk4xxmp2 rq0escxv d1544ag0 tw6a2znq s1i5eluu tv7at329')]")
  26. #friend request reject -- just in case if needed
  27. #reqs = driver.find_elements(By.XPATH, "//*[contains(@class,'l9j0dhe7 du4w35lb j83agx80 pfnyh3mw taijpn5t bp9cbjyn owycx6da btwxx1t3 kt9q3ron ak7q8e6j isp2s0ed ri5dt5u2 rt8b4zig n8ej3o3l agehan2d sk4xxmp2 rq0escxv d1544ag0 tw6a2znq tdjehn4e tv7at329')]")
  28. print(reqs)
  29. for req in reqs:
  30. print("Friend request!")
  31. time.sleep(15) #just in case you want to change your mind...
  32. webdriver.ActionChains(driver).move_to_element(req).perform()
  33. webdriver.ActionChains(driver).move_to_element(req).click().perform()
  34. time.sleep(15)
  35. print("Completed")
  36. time.sleep(500)
  37. driver.quit()