From 384b9aa93114cd38cc847cd32aa27438b0f5f9d8 Mon Sep 17 00:00:00 2001 From: hyeonggil <> Date: Fri, 27 Mar 2026 23:33:55 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20ChromeDriver=20=EA=B2=BD?= =?UTF-8?q?=EB=A1=9C=20=EC=84=A4=EC=A0=95=20=EB=B0=8F=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=20=EB=94=94=EB=A0=89=ED=86=A0=EB=A6=AC=20=EC=83=9D=EC=84=B1=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ChromeDriver 경로를 환경 변수로 설정하여 유연한 드라이버 관리 가능 - CI 및 로컬 환경에서 로그 디렉토리를 자동 생성하도록 수정 - requirements.txt에서 selenium 버전을 명시적으로 지정하여 호환성 강화 --- .github/workflows/lotto-buy.yml | 4 +++- lotto-runner/lotto_auto_buy.py | 8 +++++++- lotto-runner/requirements.txt | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lotto-buy.yml b/.github/workflows/lotto-buy.yml index fa9a967..5589a40 100644 --- a/.github/workflows/lotto-buy.yml +++ b/.github/workflows/lotto-buy.yml @@ -78,11 +78,12 @@ jobs: uses: browser-actions/setup-chrome@v1 with: install-dependencies: true - install-driver: true + install-chromedriver: true - name: Chrome 확인 run: | "${{ steps.setup-chrome.outputs.chrome-path }}" --version + "${{ steps.setup-chrome.outputs.chromedriver-path }}" --version - name: 로또 구매 실행 env: @@ -91,4 +92,5 @@ jobs: TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} CHROME_BIN: ${{ steps.setup-chrome.outputs.chrome-path }} + CHROMEDRIVER_PATH: ${{ steps.setup-chrome.outputs.chromedriver-path }} run: .venv/bin/python3 lotto-runner/lotto_auto_buy.py diff --git a/lotto-runner/lotto_auto_buy.py b/lotto-runner/lotto_auto_buy.py index 65b13b7..205c2c7 100644 --- a/lotto-runner/lotto_auto_buy.py +++ b/lotto-runner/lotto_auto_buy.py @@ -19,6 +19,9 @@ import tempfile import urllib.request from datetime import datetime +# 로그 디렉토리는 CI/로컬 어디서든 보장 +os.makedirs("logs", exist_ok=True) + # .env 파일 자동 로드 try: from dotenv import load_dotenv @@ -89,7 +92,10 @@ def create_driver(): options.add_experimental_option("excludeSwitches", ["enable-automation"]) options.add_experimental_option("useAutomationExtension", False) - driver = webdriver.Chrome(options=options) + chromedriver_path = os.environ.get("CHROMEDRIVER_PATH", "") + service = Service(executable_path=chromedriver_path) if chromedriver_path else None + + driver = webdriver.Chrome(service=service, options=options) # 종료 시 정리할 수 있도록 임시 프로필 경로 저장 driver._chrome_user_data_dir = chrome_user_data_dir driver._chrome_user_data_dir_auto_created = auto_created_profile diff --git a/lotto-runner/requirements.txt b/lotto-runner/requirements.txt index c6ffdf1..d2c5735 100644 --- a/lotto-runner/requirements.txt +++ b/lotto-runner/requirements.txt @@ -1,2 +1,2 @@ -selenium +selenium>=4.6.0 python-dotenv