Quantcast

Facebook Sent Friend Request Removal - Script Using Python Selenium

Introduction

I wanted a simple script that can cancel/remove all of my outgoing friend requests

This is useful if you are doing fb growth hacking and just have a bunch of pending requests that you need to get rid of without massive clicking. There are solutions like chrome plug-in you can download, but I like having the control in my own code!.

My solution uses Python Selenium to automate cancel clicking. It uses the mobile version of the facebook site to minimize edge conditions.

Preparation

You will need:
1) Python
2) Selenium (http://selenium-python.readthedocs.io/installation.html)
If you have pip, simply run: pip install selenium

Code
from selenium import webdriver  
import argparse

parser = argparse.ArgumentParser()  
parser.add_argument('--username', required=True)  
parser.add_argument('--password', required=True)  
args = vars(parser.parse_args())

driver = webdriver.Firefox()  
driver.implicitly_wait(30)  
base_url = "https://m.facebook.com/friends/center/requests/outgoing/#friends_center_main"

driver.get(base_url)  
driver.find_element_by_name("email").clear()  
driver.find_element_by_name("email").send_keys(args['username'])  
driver.find_element_by_name("pass").clear()  
driver.find_element_by_name("pass").send_keys(args['password'])  
driver.find_element_by_name("login").click()

while True:  
    cancelReq = driver.find_element_by_link_text("Cancel Request")
    cancelReq.click()

You enter your facebook username + password in the command prompt when you run this code:

pythong script.py --username woot@hacker.com --password VeryS3c0re  


Final note

The code was last tested working July 2016
Facebook changes stuff frequently so I can't guarantee that it'll work for long. If you are seeing error messages, go ahead and leave a comment hopefully I can help you debug the issue.