PlaybooksExtract Content as Markdown
Crawl and archive a list of documentation pages
Save what the API returns for a list of documentation pages, one JSON file per page.
Fetch several pages with their Markdown and keep what the API returns for each in a JSON file, for offline search or RAG ingestion.
import json
import os
import time
import requests
API_KEY = os.environ["CAPTUREKIT_API_KEY"]
def get(path, params):
response = requests.get(f"https://api.capturekit.dev{path}", headers={"x-api-key": API_KEY}, params=params)
if not response.ok:
raise SystemExit(f"Error {response.status_code}: {response.text}")
return response.json()
os.makedirs("docs_archive", exist_ok=True)
PAGES = [
"https://stripe.com/docs/payments",
"https://stripe.com/docs/billing",
"https://stripe.com/docs/connect",
]
for page_url in PAGES:
data = get("/v1/content", {"url": page_url, "include_markdown": "true"})["data"]
slug = page_url.rstrip("/").split("/")[-1]
path = f"docs_archive/{slug}.json"
with open(path, "w", encoding="utf-8") as file:
json.dump(data, file, ensure_ascii=False, indent=2)
print(f"Saved: {path} ({data['metadata'].get('title', slug)})")
time.sleep(1)
print("Done!")Each file keeps the Markdown of the page next to its metadata and links: split the Markdown by headings and embed the chunks to search a documentation site by meaning.