Python/Selenium Script To Remove All Reddit Comments

https://www.reddit.com/r/learnpython/comments/156jcai/pythonselenium_script_to_remove_all_reddit/

created by [deleted] on 22/07/2023 at 12:50 UTC*

0 upvotes, 5 top-level comments (showing 5)

## remove all reddit comments 
## you have to run this script anew every 100 or so comments
## as it doesnt press next ...yet                                                                                                                                                                                    
## © DeFiCaScMaTr use freely or modify or distribute or whatever

from selenium import webdriver                                                                                                                                                                                       
from selenium.webdriver.common.by import By                                                                                                                                                                          
from selenium.webdriver.support import expected_conditions as EC                                                                                                                                                     
from selenium.webdriver.support.ui import WebDriverWait                                                                                                                                                              
import time  

##declare some variables                                                                                                                                                                                              
##replace YOURUSERNAME and YOURPASSWORD with your username (as in u/YOURUSERNAME) and password                                                                                                                                                                                                                                                                                                                                             
url="https://old.reddit.com/user/YOURUSERNAME/comments/#"                                                                                                                                                            
user="YOURUSERNAME"                                                                                                                                                                                                  
password='YOURPASSWORD'                                                                                                                                                                                              

## set up headless browser                                                                                                                                                                                     
driver = webdriver.Firefox()                                                                                                                                                                                         
driver.get(url)                                                                                                                                                                                                                                                                                                                                                                                                                           
## log into the thing                                                                                                                                                                                                 
driver.find_element(By.XPATH,"/html/body/div[2]/div[3]/span[1]/a[1]").click()                                                                                                                                        

## give the log in dialog some time to pop up                                                                                                                                                                         
time.sleep(1)                                                                                                                                                                                                        
driver.find_element(By.XPATH,"//*[@id='user_login']").send_keys(user)                                                                                                                                                
driver.find_element(By.XPATH,"//*[@id='passwd_login']").send_keys(password)                                                                                                                                          

time.sleep(2) 

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH,"//button[@class='c-btn c-btn-primary c-pull-right']"))).click()


time.sleep(2)                                                                                                                                                                                                                                                                                                                                                                                                                             

while 1:                                                                                                                                                                                                                     
  WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH,'/html/body/div[4]/div[2]/*/div[2]/ul/*/form/span[1]/a'))).click()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
  WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH,"/html/body/div[4]/div[2]/*/div[2]/ul/*/form/span[2]/a[1]"))).click()

Comments

Comment by [deleted] at 22/07/2023 at 17:39 UTC

2 upvotes, 1 direct replies

[deleted]

Comment by [deleted] at 22/07/2023 at 13:02 UTC

1 upvotes, 1 direct replies

[deleted]

Comment by brunonicocam at 22/07/2023 at 19:11 UTC

0 upvotes, 0 direct replies

and the question?

Comment by nigelfarij at 22/07/2023 at 17:11 UTC

1 upvotes, 0 direct replies

What's the point in using time.sleep and WebDriverWait.

Comment by NeverStopNeverStopin at 24/07/2023 at 09:19 UTC

1 upvotes, 0 direct replies

Get rid of downvotes next and then trolls after that. Use AI to learn what you like and only show the comments that AI thinks you will like.