friend_request.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435
  1. from selenium import webdriver
  2. from selenium.webdriver.common.by import By
  3. import time
  4. def restart_browser():
  5. options = webdriver.ChromeOptions()
  6. options.add_argument("start-maximized")
  7. options.add_argument('user-data-dir=C:/Users/XXXXXXXXX/AppData/Local/Google/Chrome/User Data/') # replace XXXXXXXXX with your own username
  8. options.add_argument('--profile-directory="Profile 8"')
  9. driver=webdriver.Chrome(chrome_options=options)
  10. driver.set_window_size(1400,1000)
  11. return driver
  12. driver=restart_browser()
  13. driver.get('https://www.facebook.com/friends/requests')
  14. #friend request confirm
  15. 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')]")
  16. #friend request reject -- just in case if needed
  17. #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')]")
  18. print(reqs)
  19. for req in reqs:
  20. print("Friend request!")
  21. time.sleep(15) #just in case you want to change your mind...
  22. webdriver.ActionChains(driver).move_to_element(req).perform()
  23. webdriver.ActionChains(driver).move_to_element(req).click().perform()
  24. time.sleep(15)
  25. print("Completed")
  26. time.sleep(500)
  27. driver.quit()