구글에 색인된 게시물들을 삭제하기 위해 모든 글들을 비공개로 변경하고, 일일이 구글 서치 콘솔에서 오래된 콘텐츠를 삭제하려니 너무 노가다여서 대충 자동화함...
로그인하고 새요청 눌러서 url 입력하고 반복~
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
import undetected_chromedriver as uc
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
ID = ""
PW = ""
url = " https://search.google.com/search-console/remove-outdated-content?sjid=3899332762336075066-AP "
max_page = 877 #글 관리에서 전체 몇 페이지인지
options = uc.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
d = DesiredCapabilities.CHROME
d["goog:loggingPrefs"] = {"browser": "INFO"}
chromedriver_path = r"c:\jupyter_notebook\chromedriver116.exe"
browser = uc.Chrome(driver_executable_path=chromedriver_path, use_subprocess=True, options=options, desired_capabilities=d)
browser.maximize_window()
browser.get(url)
# #로그인 처리
WebDriverWait(browser, timeout=10).until(lambda d: d.find_element(By.XPATH, r'//*[@id="identifierId"]'))
search = browser.find_element(By.XPATH, r'//*[@id="identifierId"]')
search.send_keys(ID)
search.send_keys(Keys.RETURN)
WebDriverWait(browser, timeout=10).until(lambda d: d.find_element(By.XPATH, r'//*[@id="password"]/div[1]/div/div[1]/input'))
search = browser.find_element(By.XPATH, r'//*[@id="password"]/div[1]/div/div[1]/input')
search.send_keys(PW)
search.send_keys(Keys.RETURN)
curr_page = 1
while curr_page <= max_page:
#새요청 클릭
WebDriverWait(browser, timeout=10).until(lambda d: d.find_element(By.XPATH, r'/html/body/c-wiz/div/div[2]/div[1]/div/div[4]/button/span'))
browser.find_element(By.XPATH, r'/html/body/c-wiz/div/div[2]/div[1]/div/div[4]/button/span').click()
#url 입력하고 엔터
WebDriverWait(browser, timeout=10).until(lambda d: d.find_element(By.XPATH, r'/html/body/div[7]/div[2]/div/div[1]/div/div/div[2]/span/div[2]/label/input'))
search = browser.find_element(By.XPATH, r'/html/body/div[7]/div[2]/div/div[1]/div/div/div[2]/span/div[2]/label/input')
search.send_keys("https://ndlessrain.com/"+str(curr_page))
search.send_keys(Keys.RETURN)
time.sleep(2)
# 제출 될 때 까지 대기
WebDriverWait(browser, timeout=60).until_not(EC.visibility_of_element_located((By.XPATH, r'/div/div[1]/div/div[2]/div/button/span')))
time.sleep(3)
# 확인 클릭
WebDriverWait(browser, timeout=10).until(lambda d: d.find_element(By.XPATH, r'/html/body/div[7]/div[2]/div/div[2]/div/button/span'))
browser.find_element(By.XPATH, r'/html/body/div[7]/div[2]/div/div[2]/div/button/span').click()
time.sleep(1)
if curr_page == max_page :
sys.exit("program done")
curr_page = curr_page + 1
'Python' 카테고리의 다른 글
jupyter-server 1.13.5 requires pywinpty<2; os_name == "nt", but you have pywinpty 2.0.10 which is incompatible. (0) | 2023.11.22 |
---|---|
No module named 'binance.um_futures' (0) | 2023.11.22 |
네이버 서치어드바이저에서 전체 웹페이지 검색 제외 자동 (0) | 2023.08.25 |
undected_chromedriver에서 This version of ChromeDriver only supports Chrome version 114 오류 (0) | 2023.08.22 |
selenium4 설명 잘 되어 있는 블로그 (0) | 2023.08.22 |