Python

티스토리 모든 댓글, 방명록 지우기

ndlessrain 2025. 8. 4. 17:27
728x90

댓글이나 방명록 도배 당했을 시 사용하시기 바랍니다.

from selenium import webdriver
from seleniuhttp://m.webdriver.common.keys import Keys
from seleniuhttp://m.webdriver.common.action_chains import ActionChains
import time
from random import *
from seleniuhttp://m.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import sys
from seleniuhttp://m.webdriver.common.by import By
from seleniuhttp://m.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

blog_str = "https://ndlessrain.tistory.com"

browser = webdriver.Chrome()
browser.maximize_window()
browser.get(blog_str+"/manage/comments")

max_page = 100 #전체 댓글 페이지 수
browser.get(blog_str+"/manage/ comments ")

curr_page = 1
while curr_page <= max_page:
    #현재 페이지의 글 모두 선택
    WebDriverWait(browser, timeout=3).until(lambda d: d.find_element(By.XPATH, r'//*[@id="checkComments"]'))
    browser.find_element(By.XPATH, r'//*[@id="mArticle"]/div/div[1]/div[1]/label').click()
    #변경 클릭
    WebDriverWait(browser, timeout=3).until(lambda d: d.find_element(By.XPATH, r'//*[@id="mArticle"]/div/div[1]/div[2]/button'))
    browser.find_element(By.XPATH, r'//*[@id="mArticle"]/div/div[1]/div[2]/button').click()
    #비공개 클릭
    WebDriverWait(browser, timeout=3).until(lambda d: d.find_element(By.XPATH, r'//*[@id="mArticle"]/div/div[1]/div[2]/div/ul/li[2]/label'))    
    browser.find_element(By.XPATH, r'//*[@id="mArticle"]/div/div[1]/div[2]/div/ul/li[2]/label').click()
    
    #처리 완료될 때 까지 최대 1분 대기
    WebDriverWait(browser, timeout=60).until_not(EC.visibility_of_element_located((By.XPATH, r'//*[@id="mArticle"]/div/div[1]/div[2]/button')))
    
    if curr_page == max_page :
        sys.exit("program done")    
    
    curr_page = curr_page + 1
    
    #다음페이지 이동
    page_str = blog_str+"/manage/ comments ?page="+str(curr_page)
    
    browser.get(page_str)
    time.sleep(1)

728x90