From d6366a38f32297d1dc06a12125e17d7fd1a070a1 Mon Sep 17 00:00:00 2001 From: gahusb Date: Sat, 23 May 2026 01:17:12 +0900 Subject: [PATCH] =?UTF-8?q?fix(stock):=20=EC=9B=90=EB=8B=AC=EB=9F=AC=20?= =?UTF-8?q?=ED=99=98=EC=9C=A8=20=EB=93=B1=EB=9D=BD=20=EB=B0=A9=ED=96=A5=20?= =?UTF-8?q?=ED=8C=90=EB=B3=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 네이버 환율 HTML에 .blind span이 "미국 USD"/"원"/"상승" 3개라 select_one(".blind")이 첫 번째 "미국 USD"를 잡아 방향 추출 실패 → direction="" + 부호 없는 change_value → 프론트가 항상 상승으로 표시. 해외 지수와 동일하게 .head_info의 point_up/point_dn 클래스로 판별, 직속 .blind 텍스트(상승/하락)를 fallback으로 사용. Co-Authored-By: Claude Opus 4.7 (1M context) --- stock/app/scraper.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/stock/app/scraper.py b/stock/app/scraper.py index ae36a52..17fb571 100644 --- a/stock/app/scraper.py +++ b/stock/app/scraper.py @@ -199,11 +199,21 @@ def fetch_major_indices() -> Dict[str, Any]: value = usd_item.select_one(".value").get_text(strip=True) change_val = usd_item.select_one(".change").get_text(strip=True) - # 방향 (blind 텍스트: 상승, 하락) + # 방향: .head_info의 point_up/point_dn 클래스로 판별 (해외 지수와 동일 패턴). + # .blind span이 "미국 USD"/"원"/"상승" 3개라 select_one(".blind")은 첫 번째 "미국 USD"를 + # 잡아 방향 추출에 실패함 → head_info 클래스를 1순위로, 직속 .blind 텍스트를 fallback으로 사용. direction = "" - blind_txt = usd_item.select_one(".blind").get_text(strip=True) - if "상승" in blind_txt: direction = "red" - elif "하락" in blind_txt: direction = "blue" + head_info = usd_item.select_one(".head_info") + hi_classes = head_info.get("class", []) if head_info else [] + if "point_up" in hi_classes: + direction = "red" + elif "point_dn" in hi_classes: + direction = "blue" + else: + dir_blind = usd_item.select_one(".head_info > span.blind") + blind_txt = dir_blind.get_text(strip=True) if dir_blind else "" + if "상승" in blind_txt: direction = "red" + elif "하락" in blind_txt: direction = "blue" # change_val은 네이버 HTML에서 부호 없이 숫자만 옴 → direction 기반으로 부호 붙여줌 # (프론트 getDirection()이 부호로 색/화살표를 판별하므로)