friend_request.py 1.9 KB

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