콘텐츠로 이동
로그인 가입하기

추출 규칙

BeautifulSoup, Cheerio, 정규식은 건너뛰세요. 어떤 CSS 선택자가 어떤 JSON 필드에 매핑되는지 Shifter에 알려주면, 정제된 JSON을 그대로 돌려받습니다.

각 키가 출력 필드이고 각 값이 추출 방법을 설명하는 URL 인코딩된 JSON 객체로 extract_rules를 전달하세요.

최소 예시:

{
"title": { "selector": "h1", "output": "text" }
}

URL 인코딩 후 전송:

Terminal window
curl "https://scrape.shifter.io/v1?api_key=YOUR_API_KEY&url=https://example.com&extract_rules=%7B%22title%22%3A%7B%22selector%22%3A%22h1%22%2C%22output%22%3A%22text%22%7D%7D"
# {"title": "Example Domain"}
output반환값예시
text요소의 텍스트 콘텐츠"Example Domain"
html내부 HTML"<strong>Example</strong> Domain"
@<attr>속성 값"@href""https://example.com/"

규칙 객체에 키를 추가하세요:

{
"title": { "selector": "h1", "output": "text" },
"description": { "selector": "meta[name=description]", "output": "@content" },
"canonical": { "selector": "link[rel=canonical]", "output": "@href" }
}

응답:

{
"title": "Example Domain",
"description": "The example domain...",
"canonical": "https://example.com/"
}

리스트(검색 결과, 제품 카드, 테이블 행)의 경우, type: "list"item을 지정하는 상위 항목으로 규칙을 감싸세요:

{
"products": {
"selector": "div.product",
"type": "list",
"item": {
"name": { "selector": "h2", "output": "text" },
"price": { "selector": ".price", "output": "text" },
"link": { "selector": "a.title", "output": "@href" }
}
}
}

응답:

{
"products": [
{ "name": "Item A", "price": "$19.99", "link": "/item-a" },
{ "name": "Item B", "price": "$24.50", "link": "/item-b" }
]
}

이미 JSON을 반환하는 엔드포인트(대부분의 REST API)의 경우, auto_parser=1을 추가하면 본문을 파싱해서 그대로 반환합니다:

Terminal window
curl "https://scrape.shifter.io/v1?api_key=YOUR_API_KEY&url=https://api.example.com/products&auto_parser=1"
  • 먼저 브라우저 개발자 콘솔에서 선택자를 테스트하세요: document.querySelector(...).
  • URL 인코딩된 JSON을 올바르게 이스케이프하세요. 대부분의 HTTP 클라이언트는 규칙을 파라미터 객체로 전달할 때 이 작업을 자동으로 처리합니다.
  • 페이지에 필드가 없는 경우, 요청이 실패하는 대신 null이 반환됩니다.