Search

google sheet 클릭 자동화 연동 (1)

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(): browser = webdriver.Chrome() try: # Google Sheets 열기 spreadsheet = gc.open('프로그램 url 제작하기') worksheet = spreadsheet.worksheet('새로고침용 합격/팀공지페이지url') # C 열의 데이터 2번째부터 65번째까지 가져오기 c_column_range = worksheet.range('C2:C65') c_column_data = [cell.value for cell in c_column_range] 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() def main(): 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()
Python
복사