# Task: 블로그 검색 크롤러 셀렉터 수정 + 검색량 기준 변경

## 긴급도: critical
네이버 HTML 변경으로 Step 5 블로그 검색이 0건 반환 중. 분석 파이프라인 핵심 기능 마비.

---

## 1. 블로그 검색 URL 변경

### 파일: `/home/jay/projects/InfoKeyword/worker/crawler/blog_search.py`

**기존 (라인 13-15)**:
```python
_BLOG_SEARCH_URL = (
    "https://search.naver.com/search.naver?where=blog&query={keyword}"
)
```

**수정**:
```python
_BLOG_SEARCH_URL = (
    "https://search.naver.com/search.naver?ssc=tab.blog.all&sm=tab_jum&query={keyword}"
)
```

이유: 네이버 블로그탭 직접 URL이 더 많은 결과(30건)를 반환하고, 현재 `where=blog`는 HTML 구조가 달라 파싱 실패.

---

## 2. _parse_blog_item() 앵커 셀렉터 수정

### 파일: `/home/jay/projects/InfoKeyword/worker/crawler/blog_search.py`

**기존 (라인 93-97)**:
```python
anchor: Tag | None = (
    item.find("a", attrs={"data-heatmap-target": ".imgtitlelink"})
    or item.find("a", class_="title_link")
    or item.select_one("a.api_txt_lines")
)
```

**수정**:
```python
anchor: Tag | None = (
    item.find("a", attrs={"data-heatmap-target": ".nblg"})    # 블로그탭 일반 결과
    or item.find("a", attrs={"data-heatmap-target": ".tit"})  # 블로그탭 광고 결과
    or item.find("a", attrs={"data-heatmap-target": ".link"}) # 통합검색 블로그 영역
    or item.find("a", attrs={"data-heatmap-target": ".imgtitlelink"})  # 레거시
    or item.find("a", class_="title_link")                     # 레거시
    or item.select_one("a.api_txt_lines")                      # 레거시
)
```

### 검증된 네이버 HTML 구조 (2026-03-04 확인):
- 블로그탭(`ssc=tab.blog.all`) 일반 결과: `data-heatmap-target=".nblg"` → find()로 첫 번째(=제목) 반환
- 블로그탭(`ssc=tab.blog.all`) 광고 결과: `data-heatmap-target=".tit"` → 제목
- 통합검색(`where=blog`) 일반 결과: `data-heatmap-target=".link"` → 제목
- 컨테이너: `[data-template-id="ugcItem"]` → 정상 작동 (변경 불필요)
- 블로그명: `data-heatmap-target="articleSourceJSX_title"` → 정상 작동 (변경 불필요)

---

## 3. 광고 감지 강화 (선택)

`_is_ad()` 함수에 `articleSourceJSX_adtag` 감지 추가를 검토:
```python
# 블로그탭에서 광고 표시 태그 감지
if item.find(attrs={"data-heatmap-target": "articleSourceJSX_adtag"}):
    return True
```
현재 `_fe_view_power_content` 클래스와 `ader.naver.com` 도메인으로도 감지되므로, 기존 감지가 이미 작동함. 방어적으로 추가 권장.

---

## 4. SEARCH_VOLUME_THRESHOLD 변경

### 파일: `/home/jay/projects/InfoKeyword/worker/config.py`

**기존 (라인 35)**:
```python
SEARCH_VOLUME_THRESHOLD = 20
```

**수정**:
```python
SEARCH_VOLUME_THRESHOLD = 30
```

---

## 5. 리포트 description 문구 업데이트

### 파일: `/home/jay/projects/InfoKeyword/worker/reporter/report_generator.py`

**기존 (라인 170-171)**:
```python
description="네이버 광고 API 기준 월간 검색량 (20 이상이어야 통과)",
```

**수정**:
```python
description=f"네이버 광고 API 기준 월간 검색량 ({SEARCH_VOLUME_THRESHOLD} 이상이어야 통과)",
```
상단에 `from worker.config import SEARCH_VOLUME_THRESHOLD` import 추가 필요.

---

## 6. 검증 방법

수정 완료 후 Worker 재시작하고 테스트:

```bash
cd /home/jay/projects/InfoKeyword
source /home/jay/workspace/.env.keys
unset CLAUDECODE
python3 -c "
import asyncio
from worker.crawler.blog_search import search_blogs

async def test():
    # 일반 키워드 테스트
    blogs = await search_blogs('가공육 암')
    print(f'가공육 암: {len(blogs)} results')
    for b in blogs[:3]:
        print(f'  rank={b[\"rank\"]} is_ad={b[\"is_ad\"]} title={b[\"title\"][:40]}')

    # 광고 키워드 테스트
    blogs2 = await search_blogs('암보험 추천')
    print(f'암보험 추천: {len(blogs2)} results')
    ad_count = sum(1 for b in blogs2 if b['is_ad'])
    print(f'  ads: {ad_count}, non-ads: {len(blogs2) - ad_count}')

asyncio.run(test())
"
```

예상 결과:
- "가공육 암": 10건 (top_n=10 제한), is_ad=False
- "암보험 추천": 10건, 광고 3건 + 일반 7건

---

## 7. Worker 재시작

테스트 통과 후:
```bash
cd /home/jay/projects/InfoKeyword
pkill -f "python3 -m worker.main" || true
sleep 1
source /home/jay/workspace/.env.keys
unset CLAUDECODE
nohup python3 -m worker.main > /tmp/infokeyword-worker.log 2>&1 &
sleep 2
curl -s http://localhost:8100/health | python3 -m json.tool
```

---

## 수정 대상 파일 목록
1. `worker/crawler/blog_search.py` — URL + 셀렉터 + 광고감지
2. `worker/config.py` — SEARCH_VOLUME_THRESHOLD
3. `worker/reporter/report_generator.py` — description 문구