friend_request.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. fullpath='user-data-dir='+userdatadir
  10. # options.add_argument('user-data-dir=C:/Users/XXXXXXXXX/AppData/Local/Google/Chrome/User Data/') # replace XXXXXXXXX with your own username
  11. options.add_argument(fullpath) # replace XXXXXXXXX with your own username
  12. print(fullpath)
  13. options.add_argument('--profile-directory=Default')
  14. # options.add_argument('--profile-directory="Profile 1"')
  15. driver=webdriver.Chrome(chrome_options=options)
  16. driver.set_window_size(1400,1000)
  17. return driver
  18. config = configparser.ConfigParser()
  19. #config.sections()
  20. config.read('c:/portable/choozmo.ini')
  21. userdatadir=config['DEFAULT']['userdatadir']
  22. #for k,v in config['DEFAULT'].items():
  23. # print(k)
  24. #sys.exit()
  25. driver=restart_browser(userdatadir)
  26. driver.get('https://www.facebook.com/friends/requests')
  27. #friend request confirm
  28. 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')]")
  29. #friend request reject -- just in case if needed
  30. #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')]")
  31. print(reqs)
  32. for req in reqs:
  33. print("Friend request!")
  34. time.sleep(15) #just in case you want to change your mind...
  35. webdriver.ActionChains(driver).move_to_element(req).perform()
  36. webdriver.ActionChains(driver).move_to_element(req).click().perform()
  37. time.sleep(15)
  38. print("Completed")
  39. time.sleep(500)
  40. driver.quit()