Trafilatura

TrafilaturaTools wraps the trafilatura library to expose extract_text, extract_metadata_only, html_to_text, extract_batch, and crawl_website functions.

TrafilaturaTools enable an Agent to extract text and metadata from web pages using the Trafilatura library.

Prerequisites

The following example requires the trafilatura library.

uv pip install -U agno trafilatura openai

Example

Replace https://example.com/article with a real article URL before running. The following agent extracts and analyzes that page:

from agno.agent import Agent
from agno.tools.trafilatura import TrafilaturaTools

agent = Agent(
    instructions=[
        "You are a web content extraction specialist",
        "Extract clean text and structured data from web pages",
        "Provide detailed analysis of web content and metadata",
        "Help with content research and web data collection",
    ],
    tools=[TrafilaturaTools()],
)

agent.print_response("Extract the main content from https://example.com/article", stream=True)

Toolkit Params

ParameterTypeDefaultDescription
output_formatstr"txt"Default output format (txt, json, xml, markdown, csv, html, xmltei).
include_commentsboolTrueWhether to extract comments along with main text.
include_tablesboolTrueWhether to include table content.
include_imagesboolFalseWhether to include image information (experimental).
include_formattingboolFalseWhether to preserve text formatting.
include_linksboolFalseWhether to preserve links (experimental).
with_metadataboolFalseWhether to include metadata in extractions.
favor_precisionboolFalseWhether to prefer precision over recall.
favor_recallboolFalseWhether to prefer recall over precision.
target_languageOptional[str]NoneTarget language filter (ISO 639-1 format).
deduplicateboolFalseWhether to remove duplicate segments.
max_tree_sizeOptional[int]NoneMaximum tree size for processing.
max_crawl_urlsint10Maximum visited URLs for crawler discovery; not a cap on all discovered links or extracted output.
max_known_urlsint100000Maximum number of known URLs during crawling.
enable_extract_textboolTrueWhether to extract text content.
enable_extract_metadata_onlyboolTrueWhether to extract metadata information.
enable_html_to_textboolTrueWhether to convert HTML content to clean text.
enable_extract_batchboolTrueWhether to extract content from multiple URLs in batch.
enable_crawl_websiteboolTrueWhether to crawl a website and extract content from multiple pages.
allboolFalseEnable all tools.

Toolkit Functions

FunctionDescription
extract_textExtract main text content from a URL.
extract_metadata_onlyExtract metadata information from web pages.
html_to_textConvert HTML content to clean text.
crawl_websiteDiscover URLs by default (extract_content=False); True separately extracts content from at most 10 known links.
extract_batchExtract content from multiple URLs in batch.

Developer Resources