Callawaygolf Crawling

크롤링
스크린샷
스키마 관리
헬스체크
API 가이드

크롤링 중입니다...

스크린샷 생성 중입니다...

스키마 생성/수정

기본 정보

필드 목록

필드명 타입 입력방식 선택자 속성 필수 작업
JSON 미리보기

📚 API 가이드

Puppeteer 크롤링 시스템의 모든 API 엔드포인트 사용법을 안내합니다.

🔗 기본 정보

서버 주소: http://localhost:4920

Content-Type: application/json (POST/PUT 요청 시)

응답 형식: 모든 API는 JSON 형식으로 응답합니다.

🧪 크롤링 테스트에서 사용하는 API

현재 크롤링 테스트 페이지에서 사용하는 API는 다음과 같습니다:

  • POST /api/extract - "스키마 기반 추출" 버튼에서 사용
  • POST /api/save - "MongoDB 저장" 버튼에서 사용

💡 사용 방법: 크롤링 탭에서 클라이언트 선택 → 스키마 선택 → URL 입력 → "스키마 기반 추출" 클릭 → "MongoDB 저장" 클릭

1. 통합 크롤링 API ⭐

GET /api/crawling/

스키마 기반으로 웹페이지를 크롤링하고 자동으로 MongoDB에 저장합니다. clientIdcategory 기준으로 upsert(업데이트 또는 삽입)를 수행합니다.

쿼리 파라미터:
  • clientId: MongoDB 데이터베이스명 (필수)
  • category: 스키마 카테고리 (필수)
  • c_url: 크롤링할 URL (필수)
  • sku: 상품 SKU (선택사항, 데이터에 포함됨)
사용 예시:
GET /api/crawling/?clientId=testclient&category=gear_club&c_url=https://example.com
응답 예시:
{
  "success": true,
  "message": "크롤링 및 업데이트이 완료되었습니다.",
  "data": {
    "operation": "업데이트",
    "documentId": "68cd7f79e71efe78e5c78b04",
    "clientId": "testclient",
    "category": "gear_club",
    "url": "https://example.com",
    "extractedAt": "2025-09-19T16:05:56.502Z",
    "productCount": 8,
    "matchedCount": 1,
    "modifiedCount": 1
  }
}

2. 클라이언트 목록 조회 API

GET /api/clients

MongoDB에 등록된 모든 클라이언트 목록을 조회합니다.

응답 예시:
{
  "success": true,
  "data": [
    {
      "clientId": "callawaygolf",
      "schemaCount": 3
    },
    {
      "clientId": "testclient",
      "schemaCount": 1
    }
  ],
  "count": 2
}

3. 스키마 저장 API

POST /api/schema

크롤링 스키마를 MongoDB의 crawling_schema 컬렉션에 저장합니다.

요청 본문:
{
  "clientId": "callawaygolf",
  "category": "gear_club",
  "schema": {
    "clientId": "callawaygolf",
    "version": "1.0",
    "defaults": {
      "waitUntil": "networkidle2",
      "timeoutMs": 20000
    },
    "schemas": {
      "default": {
        "fields": {
          "prod_name": {
            "selector": "#product-details-header .product-details .name",
            "type": "text",
            "required": true
          }
        }
      }
    }
  }
}
응답 예시:
{
  "success": true,
  "message": "스키마가 성공적으로 저장되었습니다.",
  "data": {
    "insertedId": "68cd7f6ce71efe78e5c78b03",
    "category": "gear_club",
    "clientId": "callawaygolf"
  }
}

4. 스키마 리스트 조회 API

GET /api/schema/:clientId

특정 클라이언트의 모든 스키마 목록을 조회합니다.

URL 파라미터:
  • clientId: 클라이언트 ID (필수)
예시:

GET /api/schema/callawaygolf

응답 예시:
{
  "success": true,
  "data": [
    {
      "_id": "...",
      "clientId": "callawaygolf",
      "category": "gear_club",
      "name": "Gear Club",
      "version": "1.0",
      "defaults": {
        "waitUntil": "networkidle2",
        "timeoutMs": 20000
      },
      "createdAt": "2025-01-01T00:00:00.000Z",
      "schemas": {...}
    }
  ],
  "count": 3
}

5. 특정 스키마 조회 API

GET /api/schema/:clientId/:category

특정 클라이언트의 특정 카테고리 스키마를 조회합니다.

URL 파라미터:
  • clientId: 클라이언트 ID (필수)
  • category: 스키마 카테고리 (필수)
예시:

GET /api/schema/callawaygolf/gear_club

응답 예시:
{
  "success": true,
  "data": {
    "_id": "...",
    "clientId": "callawaygolf",
    "category": "gear_club",
    "name": "Gear Club",
    "version": "1.0",
    "defaults": {
      "waitUntil": "networkidle2",
      "timeoutMs": 20000
    },
    "schemas": {...}
  }
}

6. 스키마 수정 API

PUT /api/schema/:clientId/:category

특정 클라이언트의 특정 카테고리 스키마를 수정합니다.

URL 파라미터:
  • clientId: 클라이언트 ID (필수)
  • category: 스키마 카테고리 (필수)
요청 본문:
{
  "schema": {
    "clientId": "callawaygolf",
    "version": "1.1",
    "defaults": {
      "waitUntil": "networkidle2",
      "timeoutMs": 20000
    },
    "schemas": {...}
  }
}
응답 예시:
{
  "success": true,
  "message": "스키마가 성공적으로 수정되었습니다.",
  "data": {
    "matchedCount": 1,
    "modifiedCount": 1,
    "category": "gear_club",
    "clientId": "callawaygolf"
  }
}

7. 스키마 삭제 API

DELETE /api/schema/:clientId/:category

특정 클라이언트의 특정 카테고리 스키마를 삭제합니다.

URL 파라미터:
  • clientId: 클라이언트 ID (필수)
  • category: 스키마 카테고리 (필수)
예시:

DELETE /api/schema/callawaygolf/gear_club

응답 예시:
{
  "success": true,
  "message": "스키마가 성공적으로 삭제되었습니다.",
  "data": {
    "deletedCount": 1,
    "category": "gear_club",
    "clientId": "callawaygolf"
  }
}

8. 기본 크롤링 API

POST /api/crawl

웹페이지를 크롤링하여 기본 정보를 추출합니다.

헤드리스 모드 옵션:
  • "new": 새로운 헤드리스 모드 (권장, 경고 없음)
  • true: 기존 헤드리스 모드 (경고 메시지 출력)
  • false: 브라우저 창 표시 (디버깅용)
요청 본문:
{
  "url": "https://example.com",
  "headless": "new",
  "waitUntil": "networkidle2",
  "viewportWidth": 1920,
  "viewportHeight": 1080,
  "waitFor": 1000
}
응답 예시:
{
  "success": true,
  "data": {
    "url": "https://example.com",
    "title": "페이지 제목",
    "text": "페이지 텍스트 내용",
    "meta": {
      "description": "메타 설명",
      "keywords": "키워드",
      "author": "작성자"
    },
    "links": [...],
    "images": [...]
  },
  "timestamp": "2024-01-01T00:00:00.000Z"
}

9. 요소 추출 API 🧪

POST /api/extract 크롤링 테스트 사용

CSS 선택자를 사용하여 특정 HTML 요소를 추출합니다. 크롤링 테스트 페이지의 "스키마 기반 추출" 버튼에서 사용됩니다.

요청 본문:
{
  "url": "https://example.com",
  "selectors": [
    {
      "name": "product_title",
      "selector": ".product-title",
      "extractText": true,
      "extractHtml": false,
      "attributes": ["class", "id"],
      "includeIndex": false
    }
  ],
  "options": {
    "headless": "new",
    "waitUntil": "networkidle2",
    "waitFor": 1000
  }
}
응답 예시:
{
  "success": true,
  "data": {
    "product_title": [
      {
        "text": "제품 제목",
        "html": "
제품 제목
", "class": "product-title", "id": "main-title" } ] }, "timestamp": "2024-01-01T00:00:00.000Z" }

참고: 크롤링 테스트에서는 extractText: trueextractHtml: true를 모두 사용하여 텍스트와 HTML을 함께 추출합니다.

10. 스크린샷 API

POST /api/screenshot

웹페이지의 스크린샷을 생성합니다.

요청 본문:
{
  "url": "https://example.com",
  "options": {
    "width": 1920,
    "height": 1080,
    "fullPage": false
  }
}
응답:

PNG 이미지 파일 (Content-Type: image/png)

11. MongoDB 저장 API 🧪

POST /api/save 크롤링 테스트 사용

추출된 데이터를 MongoDB에 저장합니다. 크롤링 테스트 페이지의 "MongoDB 저장" 버튼에서 사용됩니다.

요청 본문:
{
  "clientId": "callawaygolf",
  "data": {
    "product": {
      "prod_name": "제품명",
      "prod_price": "가격",
      "prod_images": {...}
    }
  },
  "url": "https://example.com",
  "selectors": [...]
}
응답 예시:
{
  "success": true,
  "message": "데이터가 성공적으로 저장되었습니다.",
  "insertedId": "507f1f77bcf86cd799439011",
  "timestamp": "2024-01-01T00:00:00.000Z"
}

12. 데이터 조회 API

GET /api/data/:clientId

저장된 데이터를 조회합니다.

쿼리 파라미터:
  • limit: 조회할 문서 수 (기본값: 10)
  • skip: 건너뛸 문서 수 (기본값: 0)
예시:

GET /api/data/callawaygolf?limit=5&skip=0

응답 예시:
{
  "success": true,
  "data": [...],
  "total": 25,
  "limit": 5,
  "skip": 0,
  "timestamp": "2024-01-01T00:00:00.000Z"
}

13. 헬스체크 API

GET /api/health

서버 상태를 확인합니다.

응답 예시:
{
  "success": true,
  "message": "서버가 정상적으로 실행 중입니다.",
  "timestamp": "2024-01-01T00:00:00.000Z"
}

🗄️ MongoDB 저장 구조

모든 데이터는 clientId를 데이터베이스명으로 사용합니다.

MongoDB
└── {clientId} (데이터베이스)
    ├── crawling_schema (컬렉션) - 크롤링 스키마 정의
    │   ├── { category: "gear_club", defaults: {...}, schemas: {...} }
    │   └── { category: "apparel", defaults: {...}, schemas: {...} }
    └── crawling (컬렉션) - 크롤링된 상품 데이터
        ├── { clientId, sku, product: {...}, url, ... }
        └── { clientId, url, extractedData: {...}, ... }

스키마 저장 위치: {clientId}.crawling_schema

크롤링 데이터 저장 위치: {clientId}.crawling

Upsert 기준: {clientId, category} 기준으로 upsert

🏌️ 통합 크롤링 시스템 사용법

통합 크롤링 API를 사용하면 스키마 기반으로 웹페이지를 크롤링하고 자동으로 MongoDB에 저장할 수 있습니다.

📋 사용 단계:
  1. 클라이언트 확인: GET /api/clients로 등록된 클라이언트 목록 확인
  2. 스키마 저장: POST /api/schema로 크롤링 스키마를 저장
  3. 스키마 확인: GET /api/schema/:clientId로 저장된 스키마 목록 확인
  4. 크롤링 실행: GET /api/crawling/로 스키마 기반 크롤링 및 저장
  5. 데이터 조회: GET /api/data/:clientId로 저장된 데이터 확인
🎯 Callaway Golf 스키마 예시:
  • 제품명: #product-details-header .product-details .name
  • 가격: #product-details-header .pricerange
  • 이미지: #product-images-main-pdp .config-image-slide img
  • 기술 사양: #techSpecs + div
  • 제품 사양 테이블: #spec-info
💡 실제 사용 예시:
# 1. 클라이언트 목록 조회
curl "http://localhost:4920/api/clients"

# 2. 스키마 저장
curl -X POST http://localhost:4920/api/schema \
  -H "Content-Type: application/json" \
  -d '{
    "clientId": "callawaygolf",
    "category": "gear_club",
    "schema": {
      "clientId": "callawaygolf",
      "version": "1.0",
      "defaults": {
        "waitUntil": "networkidle2",
        "timeoutMs": 20000
      },
      "schemas": {
        "default": {
          "fields": {
            "prod_name": {
              "selector": "#product-details-header .product-details .name",
              "type": "text",
              "required": true
            }
          }
        }
      }
    }
  }'

# 3. 스키마 목록 조회
curl "http://localhost:4920/api/schema/callawaygolf"

# 4. 특정 스키마 조회
curl "http://localhost:4920/api/schema/callawaygolf/gear_club"

# 5. 크롤링 실행 (upsert)
curl "http://localhost:4920/api/crawling/?clientId=callawaygolf&category=gear_club&c_url=https://example.com"

# 6. 데이터 조회
curl "http://localhost:4920/api/data/callawaygolf?limit=10&skip=0"

# 7. 같은 clientId와 category로 다시 크롤링 (업데이트됨)
curl "http://localhost:4920/api/crawling/?clientId=callawaygolf&category=gear_club&c_url=https://example.com"

# 8. 스키마 수정
curl -X PUT http://localhost:4920/api/schema/callawaygolf/gear_club \
  -H "Content-Type: application/json" \
  -d '{"schema": {...}}'

# 9. 스키마 삭제
curl -X DELETE "http://localhost:4920/api/schema/callawaygolf/gear_club"