1. vs code 로 실행합니다.
2. 크롬 드라이버 다운 https://chromedriver.chromium.org/downloads → 폴더 경로 세팅
2. 가상환경 세팅 필요합니다. (시스템 환경 설정 확인)
python3 -m venu myenv
HTML
복사
3. python3, pip 3 세팅 필요합니다.
pip install selenium
HTML
복사
import time
from selenium import webdriver # type: ignore
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
#상세페이지 자동 클릭
URL = "https://app.oopy.io/signin"
def main():
# 브라우저 열기
browser = webdriver.Chrome()
# browser.maximize_window()
# URL로 이동
browser.get(URL)
time.sleep(2)
try:
popup_element = WebDriverWait(browser, 10).until(
EC.presence_of_element_located((By.CLASS_NAME, "css-nqcv3s"))
)
button_cookie = browser.find_element(By.CLASS_NAME, 'css-1lrvpi6')
button_cookie.click()
except Exception as e:
print("Popup or button not found", e)
id_login = browser.find_element(By.CLASS_NAME, 'css-ao0wyh')
id_login.click()
time.sleep(2)
email_input = browser.find_element(By.CSS_SELECTOR, '[data-cy="email-input"]')
email_input.send_keys("brcord@naver.com")
password_input = browser.find_element(By.CSS_SELECTOR, '[data-cy="password-input"]')
password_input.send_keys("Cgmap1230!")
time.sleep(2)
login_button = browser.find_element(By.CLASS_NAME, 'css-gd80vc')
login_button.click()
try:
popup_element1 = WebDriverWait(browser, 5).until(
EC.presence_of_element_located((By.CLASS_NAME, "css-1q8ethd"))
)
button_popup1 = browser.find_element(By.CLASS_NAME, 'css-fy95ja')
button_popup1.click()
time.sleep(5)
except Exception as e:
print("Popup or button not found", e)
refresh_url_list = [
"0659035b-a4d1-4e95-9442-7eb83edafb64",
"5c25d7a5-1253-4921-8ed2-5019d836e7c8",
"b3e66e6a-f1c5-4d21-b666-b5ddf9d93d30",
"5c8f0236-835a-4c36-af53-02cbc18dfb24",
"99bc17d1-ded1-4ec8-a658-c04c897a9955",
"7f7e1e13-8b3a-47c4-8e6b-5ff852372612",
"2da13684-5d2b-4cdd-abd2-1e138fc4c338",
"9e61dd60-3996-462d-9d4f-c77356164d73",
"7f66a2fd-570f-4280-8c77-872c6229d4f5",
"6213bb5b-d444-4818-bdb5-5f37161e0f09",
"3c57aaea-5db4-417b-8c4c-2756c0bacf3c",
"a4f44826-1279-4142-90b9-d7c00da28c33",
"dfa60285-0651-46dd-bf71-aff11fa76d6c",
"a37fe8c0-a48b-4ed7-91a5-dcbf99dcb931",
"9d803293-cb5e-4ca6-95a4-1f4d1ef09eab",
"789c5d67-9d65-45af-8930-4bc4882e167d",
"ba747a96-2158-4028-b4d3-f35998ca4e43",
"da8f1170-5611-4650-b399-cc7219a38207",
"d30d92c1-0e0c-4ffc-8c55-5fa230fb9d06",
"0dc5d3a3-df33-45fc-b3c0-7d11931932a2",
"cfa1a764-b461-4b66-a793-2f1419889b3a",
"73592003-adca-47e2-9b03-851e38fb1419",
"ae69c29a-4dd2-410e-b969-1542b6d73094",
"c0a81cc5-9ef3-41fa-bda7-8388cb3f839a",
"94f566f2-0677-4af7-8a95-50bcba5c5d50",
"2ebd5445-175a-4bff-836c-428be0c36539",
"350ad125-a04e-4f3f-86c8-187815ea31e3",
"87640030-bbc9-4b20-8673-a046a33c8288",
"3f18a0f9-1124-4d01-ae3f-92fd0b8334b4",
"748f1d7a-8b5f-48d2-8fce-09bacdc03540",
"d26ff491-73f9-46ab-a208-2d4455dbdfd9",
"09e6fc57-a3bf-4d8e-b67b-ef54a8fee0c2",
"f1729132-e9f1-4a39-a4ac-d1b1e0afc5cd",
"3837a2d2-91ae-4c2d-a300-c286b7c3ddb9",
"578477a1-a064-4fac-8008-a3db67f03d08",
"049b6133-9831-4715-9e64-fc24e9e327b3",
"65c71142-0858-43fc-99e0-057c0cf68e57",
"f236fe9e-3668-4b60-9974-ea5cc3b752e3",
"48d7c0de-6689-4648-be35-b023047e418f",
"dcdeff3c-7024-43a1-a4b0-d9bf21f541cf",
"c41dc32f-a1b5-494a-89f6-cd1d48385d6d",
"168c4704-e3cc-4989-b7b9-31229dc7cbc6",
"8c7a392a-2745-4132-90c6-e1557b32ee62",
"587f3be8-b22e-4e8d-ad48-45ba73e90c7c",
"a9c44e00-fb52-4213-9b72-18e14136408a",
"74b65177-b692-4cb4-a777-5188ed424b97",
"32a6d7ef-ef12-4180-9fe7-fd02cf5f18d1",
"e4c2653c-570d-417f-af12-2cc425a73df3",
"ccc094ac-2aca-4318-b892-322ad37ab408",
"479b72c4-0b4f-44bd-b106-b1fc8a375944",
"bd80d1aa-a49c-4c99-b2f9-a691f03b9395",
"fba03ace-8b3a-4819-95a0-5e4077e97540",
"559d02de-474c-4899-8fd7-1f721c494d69",
"dd85d3b6-27c0-4a3c-a39c-aaa7dffb0b8a",
"e98826cc-5cd7-4c59-a9a0-8ca143de1de5",
"09444b82-69b9-4d48-a593-94b5d71b847c",
"49011648-e6cd-40d6-9130-dba43de2aa4f",
"de22c88b-8d84-4b77-9a67-797d22403175",
"b0dcd82c-15ef-4334-b552-1549f2d0372b",
"9d43545b-7e24-4733-bbf5-c0f95d05e65d",
"76422a22-889e-4845-87d5-71c58a0f0e2f",
"ad40b33c-a75c-4369-8a08-704be4e8ecb7",
"a97f9da4-bb46-4628-92da-dbcda8559070",
"7b9e2097-c8c9-4ece-982b-d0674eacf75e",
"625c3616-ff3d-47c5-aa72-ba64b9d6700a",
"9d01e0ed-03c9-4803-8a96-30de551c427d",
"d07f0227-d14b-48e7-bba8-abeb9c57aa94",
"582c9a08-97ab-4623-a72b-c59df7601bf6",
"e06a17f0-d7fa-4c1f-bceb-cfb6ff86e026",
"aad0abb4-67dd-4e85-a739-e1876c1834c1",
"6621683b-b75e-49e0-959b-8d0c72fc5f4a",
"7c018689-48e2-4194-9b36-d4c6928c3aac",
"346fefd9-1937-476b-b714-12f83bbb5021",
"7958d07d-42d4-40fa-8db0-decb032d9dfd",
"7483d398-34b9-4c56-880c-4b987e9278ae",
"60010257-2277-4fce-8a71-65094071d0cf",
"48052f6e-0b02-43cb-9ac2-8ac40a0ff672",
"71360934-f2b3-4ca2-8383-09236f672f37"
]
domain_input = browser.find_element(By.CLASS_NAME, 'css-9tgohh')
for url in refresh_url_list:
domain_input.click()
browser.execute_script("arguments[0].value = '';", domain_input)
time.sleep(5)
length = len(domain_input.get_attribute("value"))
for _ in range(length):
domain_input.send_keys(Keys.BACKSPACE)
time.sleep(3)
domain_input.send_keys(url)
time.sleep(3)
# JavaScript를 사용하여 Enter 키를 시뮬레이션
#browser.execute_script("arguments[0].dispatchEvent(new Event('keydown', {keyCode: 13, which: 13}));", domain_input)
domain_input.send_keys(Keys.ENTER)
#button_go = browser.find_element(By.CLASS_NAME, 'css-1ygwv2j')
#button_go.click()
time.sleep(3)
WebDriverWait(browser, 2).until(
EC.invisibility_of_element_located((By.CLASS_NAME, 'loader'))
)
refresh_button = WebDriverWait(browser, 2).until(
EC.element_to_be_clickable((By.CLASS_NAME, 'renderer-preview-cache-refresh'))
)
refresh_button.click()
time.sleep(14)
browser.quit()
if __name__ == "__main__":
main()
HTML
복사
@제리 CX
import gspread
from google.oauth2.service_account import Credentials
from gspread.exceptions import SpreadsheetNotFound
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# 최종본
# 절대 경로로 JSON 키 파일 경로 설정
json_key_file_path = '/Users/mad-book/Desktop/testCode/click-event-428509-a3ef8ccc1374.json'
# 필요한 권한 범위 설정
scopes = [
"https://www.googleapis.com/auth/spreadsheets", # 기본 범위
"https://www.googleapis.com/auth/drive" # 추가적인 범위 (예시)
]
# 서비스 계정 인증
credentials = Credentials.from_service_account_file(json_key_file_path, scopes=scopes)
gc = gspread.authorize(credentials)
# 도메인 리스트
domains = [
]
def main():
# Chrome WebDriver를 시작합니다.
browser = webdriver.Chrome()
try:
# Google Sheets 열기
spreadsheet = gc.open('프로그램 url 제작하기')
worksheet = spreadsheet.worksheet('새로고침용 합격/팀공지페이지url')
# C 열의 데이터 2번째부터 65번째까지 가져오기
c_column_range = worksheet.range('C34:C89')
c_column_data = [cell.value for cell in c_column_range]
# 가져온 데이터를 domains 리스트에 추가
for data in c_column_data:
domains.append(data)
# 각 도메인에 접근합니다.
for domain in domains:
browser.get(domain)
print(f"Accessing: {domain}")
try:
# 페이지가 완전히 로드될 때까지 기다립니다.
WebDriverWait(browser, 10).until(
EC.presence_of_element_located((By.TAG_NAME, "body"))
)
print(f"Successfully accessed: {domain}")
except Exception as e:
print(f"Error accessing {domain}: {e}")
# 도메인별 작업 후 잠시 대기
time.sleep(2)
finally:
# 브라우저를 닫습니다.
browser.quit()
if __name__ == "__main__":
main()
def main():
# Chrome WebDriver를 시작합니다.
browser = webdriver.Chrome()
try:
for domain in domains:
# 각 도메인에 접근합니다.
browser.get(domain)
print(f"Accessing: {domain}")
# 페이지가 완전히 로드될 때까지 기다립니다 (예: 특정 요소가 나타날 때까지).
try:
WebDriverWait(browser, 10).until(
EC.presence_of_element_located((By.TAG_NAME, "body"))
)
print(f"Successfully accessed: {domain}")
except Exception as e:
print(f"Error accessing {domain}: {e}")
# 도메인별 작업 후 잠시 대기
time.sleep(2)
finally:
# 브라우저를 닫습니다.
browser.quit()
if __name__ == "__main__":
main()
HTML
복사