rs-trafilatura를 crawl4ai와 함께 사용하는 방법

발행: (2026년 4월 3일 PM 11:19 GMT+9)
4 분 소요
원문: Dev.to

I’m happy to help translate the article, but I need the full text you’d like translated. Could you please paste the content (excluding the source line you already provided) here? Once I have it, I’ll translate it into Korean while preserving the formatting, markdown, and any code blocks or URLs unchanged.

설치

pip install rs-trafilatura crawl4ai

만약 crawl4ai를 처음 사용한다면, Playwright 브라우저도 설치하세요:

python -m playwright install chromium

RsTrafilaturaStrategy를 사용한 기본 사용법

import json
import asyncio
from crawl4ai import AsyncWebCrawler, CrawlerRunConfig
from rs_trafilatura.crawl4ai import RsTrafilaturaStrategy

async def main():
    strategy = RsTrafilaturaStrategy()
    config = CrawlerRunConfig(extraction_strategy=strategy)

    async with AsyncWebCrawler() as crawler:
        result = await crawler.arun(url="https://example.com", config=config)

    data = json.loads(result.extracted_content)
    item = data[0]

    print(f"Title: {item['title']}")
    print(f"Page type: {item['page_type']}")
    print(f"Quality: {item['extraction_quality']}")
    print(f"Content: {item['main_content'][:200]}")

asyncio.run(main())

extracted_content 필드는 추출 결과를 담은 단일 항목을 가진 JSON 배열입니다. Crawl4ai가 자동으로 직렬화해 주므로, json.loads()만 하면 됩니다.

Extraction result fields

FieldDescription
title페이지 제목
author저자 이름 (감지된 경우)
date발행일 (ISO 8601)
main_content정제된 추출 텍스트
content_markdown마크다운 출력 (활성화된 경우)
page_typearticle, forum, product, collection, listing, documentation, service
extraction_quality0.0 – 1.0 신뢰도 점수
language감지된 언어
sitename사이트 이름
description메타 설명

일반 텍스트와 함께 마크다운 가져오기

strategy = RsTrafilaturaStrategy(output_markdown=True)
config = CrawlerRunConfig(extraction_strategy=strategy)

async with AsyncWebCrawler() as crawler:
    result = await crawler.arun(url="https://example.com", config=config)

data = json.loads(result.extracted_content)
markdown = data[0]["content_markdown"]

마크다운은 GitHub‑Flavored이며, 헤딩, 리스트, 테이블, 굵게/기울임, 코드 블록 및 링크를 보존합니다.

정밀도 vs. 재현율 조정

  • 더 엄격한 필터링 (노이즈 감소, 일부 콘텐츠를 놓칠 수 있음):

    strategy = RsTrafilaturaStrategy(favor_precision=True)
  • 더 포괄적인 필터링 (더 많은 콘텐츠를 포착하지만 보일러플레이트가 포함될 수 있음):

    strategy = RsTrafilaturaStrategy(favor_recall=True)

동시성 예제

async def main():
    strategy = RsTrafilaturaStrategy(output_markdown=True)
    config = CrawlerRunConfig(extraction_strategy=strategy)

    urls = [
        "https://example.com/blog/post-1",
        "https://example.com/products/widget",
        "https://example.com/docs/getting-started",
        "https://forum.example.com/thread/123",
    ]

    async with AsyncWebCrawler() as crawler:
        for url in urls:
            result = await crawler.arun(url=url, config=config)
            data = json.loads(result.extracted_content)
            item = data[0]
            print(f"[{item['page_type']}] {item['title']} (quality: {item['extraction_quality']:.2f})")

asyncio.run(main())

각 페이지는 적절한 프로필에 따라 분류 및 추출됩니다 (제품 페이지는 JSON‑LD 폴백을 사용하고, 포럼 스레드는 댓글을 콘텐츠로 처리하며, 문서 페이지는 사이드바가 제거됩니다). 추출은 페이지당 별도의 스레드에서 실행되므로 비동기 크롤링 루프를 차단하지 않습니다.

LLM 폴백이 포함된 하이브리드 파이프라인

from crawl4ai.extraction_strategy import LLMExtractionStrategy

async def extract_with_fallback(crawler, url, config):
    result = await crawler.arun(url=url, config=config)
    data = json.loads(result.extracted_content)
    item = data[0]

    if item["extraction_quality"]

리소스

  • rs‑trafilatura 소스:
  • Rust 크레이트:
  • crawl4ai 저장소:
  • WCEB 벤치마크:
  • 벤치마크 데이터 (Zenodo): (실제 DOI로 교체)
0 조회
Back to Blog

관련 글

더 보기 »