728x90

2차 도메인 쓰면서 검색엔진들이 꼬인 것 같아 모든 글을 비공개로 변경해서 색인 없애고,

몇주 후에 다시 공개로 풀어서 색인해보려 함.

글이 많은데 한번에 비공개 전환하는 기능이 안보여서, selenium으로 대충 짜봄.

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

ID = ""
PW = ""
blog_str = "https://ndlessrain.tistory.com"
max_page = 58 #글 관리에서 전체 몇 페이지인지

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

#카카오계정 로그인 클릭
WebDriverWait(browser, timeout=3).until(lambda d: d.find_element(By.XPATH, r'//*[@id="cMain"]/div/div/div/a[2]'))
browser.find_element(By.XPATH, r'//*[@id="cMain"]/div/div/div/a[2]').click()

#로그인 처리
WebDriverWait(browser, timeout=3).until(lambda d: d.find_element(By.XPATH, r'//*[@id="loginId--1"]'))
search = browser.find_element(By.XPATH, r'//*[@id="loginId--1"]')

search.send_keys(ID)

search = browser.find_element(By.XPATH, r'//*[@id="password--2"]')
search.send_keys(PW)
search.send_keys(Keys.RETURN)

#2차 인증(휴대폰)
WebDriverWait(browser, timeout=30).until(lambda d: d.find_element(By.XPATH, r'//*[@id="mArticle"]/div/div[2]/form/button'))
browser.find_element(By.XPATH, r'//*[@id="mArticle"]/div/div[2]/form/button').click()

time.sleep(1)

browser.get(blog_str+"/manage/posts")

curr_page = 1
while curr_page <= max_page:
    #현재 페이지의 글 모두 선택
    WebDriverWait(browser, timeout=3).until(lambda d: d.find_element(By.XPATH, r'//*[@id="mArticle"]/div/div[1]/div[1]/label'))
    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]/span/span')))
    
    if curr_page == max_page :
        sys.exit("program done")    
    
    curr_page = curr_page + 1
    
    #다음페이지 이동
    page_str = blog_str+"/manage/posts?category=-3&page="+str(curr_page)+"&searchKeyword=&searchType=title&visibility=all"
    
    browser.get(page_str)
    time.sleep(1)

728x90

+ Recent posts