M1: scrape spine — renderer, extractor, orchestrator /scrape, compose, health, render cache

- renderer: Node/Playwright, single browser + pooled contexts with concurrency
  cap and FIFO queue, Redis render cache (graceful no-op without Redis)
- extractor: FastAPI + Trafilatura, HTML -> {title, text, metadata}
- orchestrator: /scrape (render -> extract) with per-stage trace, aggregated
  /health, structured JSON logging on all services
- docker-compose for orchestrator/renderer/extractor/redis with healthchecks

Verified locally: end-to-end scrape of example.com and Wikipedia; error paths
for unreachable hosts and bad schemes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
User 2026-07-05 22:02:38 -07:00
parent 55317f3f75
commit e2b329b2bb
20 changed files with 1534 additions and 0 deletions

View file

@ -0,0 +1,37 @@
"""Trafilatura-based extraction. M1: primary extractor only; M2 adds fallbacks."""
import trafilatura
def extract_content(html: str, url: str) -> dict:
text = trafilatura.extract(
html,
url=url,
include_tables=True,
include_links=False,
include_comments=False,
favor_recall=False,
)
meta = trafilatura.extract_metadata(html, default_url=url)
metadata = {}
title = None
if meta is not None:
title = meta.title
metadata = {
k: v
for k, v in {
"author": meta.author,
"date": meta.date,
"sitename": meta.sitename,
"description": meta.description,
}.items()
if v
}
return {
"title": title,
"text": text or "",
"metadata": metadata,
"extractor_used": "trafilatura" if text else "none",
}