Skip to content
Go To Dashboard

Web Scraping

Web Scraping lets a deployed agent read a known URL without operating a browser. Agent steps call the typed ctx.sapiom.search.scrape capability; Sapiom supplies the authenticated cloud connection when the deployed agent runs.

What the agent needsRecommended input or capability
Clean text for extraction or summarizationformats: ["markdown"]
Cleaned markup and document structureformats: ["html"]
The original page markupformats: ["rawHtml"]
Main article content without surrounding navigationonlyMainContent: true
A fixed delay before the page is readwaitFor in milliseconds
Clicks, forms, login state, or multi-page interactionBrowser Automation

Scrape when the URL is already known and reading is enough. Use Web Search to discover URLs and Browser Automation when the task depends on interaction or a persistent session.

const page = await ctx.sapiom.search.scrape({
url: input.articleUrl,
formats: ["markdown"],
onlyMainContent: true,
});
if (!page.markdown) {
throw new Error(`No markdown returned for ${page.url}`);
}
return {
sourceUrl: page.metadata.sourceUrl ?? page.url,
title: page.metadata.title ?? null,
statusCode: page.metadata.statusCode ?? null,
markdown: page.markdown,
};

Markdown is the default format when formats is omitted. A requested content field is still optional in the result, so check the field before using it. Metadata can include the title, description, language, source URL, and HTTP status code.

const page = await ctx.sapiom.search.scrape({
url: input.pageUrl,
formats: ["html", "rawHtml"],
waitFor: 1_500,
});
return {
cleanedHtml: page.html ?? null,
originalHtml: page.rawHtml ?? null,
};

waitFor delays the read; it does not click a consent dialog, submit a form, or prove that an application reached a particular state. Use a browser session for stateful behavior.

Local Run replaces ctx.sapiom.search.scrape with a deterministic response. The built-in stub returns fixture markdown and metadata for the requested URL; it does not fetch that URL or render a page.

Override search.scrape when the step consumes a particular format or metadata branch:

{
"version": 1,
"steps": {
"read-article": {
"search.scrape": {
"url": "https://example.com/article",
"markdown": "# Fixture article\n\nVerified test content.",
"metadata": {
"title": "Fixture article",
"sourceUrl": "https://example.com/article",
"statusCode": 200
}
}
}
}
}

The override is returned verbatim. Supply every field the step consumes, assert the terminal output, and require both unusedStubs and stubWarnings to be empty. A passing Local Run does not prove that the live page is reachable, readable, or unchanged.

Scrape only URLs the agent actually needs. Prefer main-content extraction for long articles, avoid repeatedly reading the same page within one run, and retain the source URL beside derived data. If the result must outlive the run, store the derived artifact in File Storage, Data, or a Repository.

Use the signed-in capability catalog for current availability, limits, and pricing. Target-site behavior is separate from capability availability, so inspect the failed production step when a URL cannot be read.