Automating cancelling oldest friend requests on facebook

Joined
Feb 1, 2023
Messages
1
Reaction score
0
Hi all,
I'm completely new to coding and would like to create a simple automation that will save me hours of work every month. The automation involves opening Chrome on Mac, going to https://www.facebook.com/friends/requests --> view sent requests, scroll to the bottom, and click on cancel request for a new person every 5 seconds. The code should also include scrolling up when requests to all 5 people that are visible on the scree have been clicked, and the process should continue for 30min.
Would be super grateful if someone could write it for me!! Not sure if python is the best way to go - if something else is better, please let me know :)
Boyan
 
Joined
Feb 1, 2023
Messages
4
Reaction score
0
You could consider using a browser automation tool like Selenium, which allows you to programmatically control a web browser and automate tasks.

Here's the code for Selenium, change "https://www.example.com" to whichever address you need:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

# Open a Chrome browser and navigate to a website
driver = webdriver.Chrome()
driver.get("https://www.example.com")

# Interact with the website elements
element = driver.find_element_by_name("q")
element.send_keys("Selenium automation")
element.send_keys(Keys.RETURN)

# Wait for 5 seconds
time.sleep(5)

# Close the browser
driver.close()
 
Joined
Jan 30, 2023
Messages
107
Reaction score
13
You can use the Python Selenium library for automating the process in Chrome.
Hi all,
I'm completely new to coding and would like to create a simple automation that will save me hours of work every month. The automation involves opening Chrome on Mac, going to https://www.facebook.com/friends/requests --> view sent requests, scroll to the bottom, and click on cancel request for a new person every 5 seconds. The code should also include scrolling up when requests to all 5 people that are visible on the scree have been clicked, and the process should continue for 30min.
Would be super grateful if someone could write it for me!! Not sure if python is the best way to go - if something else is better, please let me know :)
Boyan

Python:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

# initialize the driver
driver = webdriver.Chrome()

# open the website
driver.get("https://www.facebook.com/friends/requests")

# wait for the page to load
time.sleep(5)

# find the "view sent requests" button and click it
view_requests_button = driver.find_element_by_xpath("//a[text()='View Sent Requests']")
view_requests_button.click()

# wait for the page to load
time.sleep(5)

# find the "cancel request" buttons and click them
cancel_request_buttons = driver.find_elements_by_xpath("//button[text()='Cancel Request']")
start_time = time.time()
while time.time() - start_time < 30 * 60:
    for i, button in enumerate(cancel_request_buttons):
        button.click()
        time.sleep(5)
        if (i + 1) % 5 == 0:
            driver.execute_script("window.scrollTo(0, 0);")
            time.sleep(5)
            cancel_request_buttons = driver.find_elements_by_xpath("//button[text()='Cancel Request']")

# close the driver
driver.quit()


Note: This code is just a sample and may need to be adjusted to work correctly with your version of Chrome and Facebook
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top