Reading the CrawlResult
A CrawlResult carries more than markdown. Here is how to read each field and which representation to use for which job.
Concept
CrawlResult is a Pydantic model that bundles the final URL, success flag, HTTP status, raw HTML, cleaned HTML, a markdown result object, media, links, metadata, and captured network or console data. Treat it as the single source of truth for what happened during the crawl.
The markdown field is itself a MarkdownGenerationResult. It exposes raw_markdown, markdown_with_citations, references_markdown, fit_markdown, and fit_html. The fit_* variants only appear when a content filter or extraction strategy produced them. media and links are dictionaries; use .get() with a fallback to avoid KeyError.
Use cases
- Feed cleaned markdown into an LLM pipeline without navigation chrome.
- Extract all internal links for a site map.
- Save page screenshots and PDFs from the same result object.
Video walkthrough
Code example
import asyncio
import json
from crawl4ai import AsyncWebCrawler, CrawlerRunConfig
async def main():
async with AsyncWebCrawler() as crawler:
result = await crawler.arun(
url="https://example.com",
config=CrawlerRunConfig(),
)
if not result.success:
print("Crawl failed:", result.error_message)
return
print("URL:", result.url)
print("Status:", result.status_code)
print("Title:", result.metadata.get("title"))
print("HTML length:", len(result.html))
print("Cleaned HTML length:", len(result.cleaned_html or ""))
if result.markdown:
print("Raw markdown length:", len(result.markdown.raw_markdown))
if result.markdown.fit_markdown:
print("Fit markdown length:", len(result.markdown.fit_markdown))
images = result.media.get("images", [])
print("Images found:", len(images))
internal = result.links.get("internal", [])
print("Internal links:", len(internal))
asyncio.run(main())
Practice lab
Practice lab
Objective: Crawl a page and print a structured summary of its CrawlResult fields.
Steps
- Crawl any allowed public page with a default
CrawlerRunConfig. - If
result.successis true, print the URL, status code, and page title. - Print the lengths of
html,cleaned_html, andraw_markdown. - Print the counts of images, internal links, and external links.
Success criteria
Expected output
Hints
- Use
result.metadata.get('title')for the page title. - External links live in
result.links.get('external', []).
Solution
import asyncio
from crawl4ai import AsyncWebCrawler, CrawlerRunConfig
async def main():
async with AsyncWebCrawler() as crawler:
result = await crawler.arun(
url="https://example.com",
config=CrawlerRunConfig(),
)
if not result.success:
print("Failed:", result.error_message)
return
md = result.markdown
print(f"URL: {result.url}")
print(f"Status: {result.status_code}")
print(f"Title: {result.metadata.get('title')}")
print(f"HTML: {len(result.html)} chars")
print(f"Cleaned HTML: {len(result.cleaned_html or '')} chars")
print(f"Raw markdown: {len(md.raw_markdown)} chars")
print(f"Images: {len(result.media.get('images', []))}")
print(f"Internal links: {len(result.links.get('internal', []))}")
print(f"External links: {len(result.links.get('external', []))}")
asyncio.run(main())
Common mistakes
result.markdown.result.markdown is a plain string; it is a result object.result.links['internal'] without a fallback, which raises KeyError if the key is absent.