webclaw

Scrape

Extract content from a single URL. This is the core endpoint -- one URL in, clean structured content out.

POST/v1/scrape

Extract content from a single URL in one or more output formats.

Markdown and structured extraction

Request extract alongside Markdown to get both from the same page. Provide an extract object with a JSON Schema, a nonempty prompt, or both. The page costs one credit, including extraction. The response includes extract beside the requested content, metadata and cache status. Unknown request fields return an error.

json
{
  "url": "https://example.com",
  "formats": ["markdown", "extract"],
  "extract": {
    "prompt": "Extract the main heading",
    "schema": {
      "type": "object",
      "properties": { "title": { "type": "string" } },
      "required": ["title"]
    }
  }
}

The existing Extract endpoint remains available with its data response envelope.

Request body

json
{
  "url": "https://example.com",
  "formats": ["markdown", "llm", "text", "json"],
  "include_selectors": [".article-content"],
  "exclude_selectors": ["nav", ".sidebar"],
  "only_main_content": true
}

Parameters

FieldTypeRequiredDescription
urlstringYesThe URL to scrape.
formatsstring[]NoOutput formats to include. Options: markdown, llm, text, json, extract (with extraction options). Defaults to ["markdown"].
include_selectorsstring[]NoCSS selectors to extract exclusively. Only content matching these selectors will be included.
exclude_selectorsstring[]NoCSS selectors to remove from the page before extraction.
only_main_contentbooleanNoDefaults to false: automatic cleanup can still remove headers and footers. When true, selects the first article, main, or role=main element and keeps its scope even when short or empty. If none exists, uses automatic extraction. Include selectors take precedence; exclusions still apply.
antibotbooleanNoDefaults to true. Set false to fetch only pages that allow automated access: Webclaw makes no attempt to get past bot protection, and a protected page returns 502 with error_code bot_protection_skipped right away. When the site refused with 401, 403, 429 or 503, target_status holds that code. Cannot be combined with actions or screenshot.
cookiesstring[]NoCookies to send to this URL's site, as name=value strings or a pasted Cookie header, to read pages behind your own login. Sent only to that host. Without it, a saved login for the site is used. The result then includes authenticated: true. Cannot be combined with actions or screenshot.
actionsobject[]NoBrowser steps to run in order before extraction, such as clicking a button and waiting for the content it reveals. See Browser actions.
Tip
Use formats for an array, or format for one string. Omission or an empty array defaults to Markdown. Supplying both, null, the wrong type, or an unsupported name returns 400. The text and llm formats use top-level response fields; json uses extraction. Additional formats are links, rawHtml, attributes, and query. Request a screenshot with the separate screenshot: true parameter. Query and attributes cannot be combined with actions or screenshots; these combinations return 400.

Detected empty default extractions and recognized access, login, or upstream errors can return 502 with an error_code, including empty_content, bot_protection_unbypassed, bot_protection_skipped, upstream_error_page, upstream_http_error, or login_required. upstream_http_error means the target answered with an HTTP error; target_status holds its status code. An include selector or a matching main region may intentionally return empty content. Target-site availability varies; check the content before treating a scrape as complete.

Tip
The llm format runs a content optimization pipeline that strips images, collapses whitespace, and deduplicates links. Token savings depend on the page and tokenizer; check that the result retains the information your task needs.

Browser actions

Some content only appears after you interact with the page: a phone number behind a "Show number" button, a list that loads on scroll, a result behind a search box. Pass an actions array and Webclaw loads the page in a real browser, runs each step in order, then extracts the final page. Each action is an object with a type and the fields below. Field names are case-sensitive and unknown fields return 400.

typeFieldsDescription
clickselector (string, required)Clicks the first element matching the CSS selector.
typeselector (string, required), value (string, required)Types value into the first element matching the selector, such as a search box.
waitmilliseconds (number, required)Pauses for a fixed time, 0 to 60000 ms. Prefer waitForSelector when you know what to wait for.
waitForSelectorselector (string, required), timeout (number, optional)Waits until an element matching the selector exists. timeout is in milliseconds, 1 to 60000, default 5000. The selector can be up to 4096 bytes.
scrolldirection (string, optional), amount (number, optional)Scrolls the page. direction is "down" (default) or "up"; amount is in pixels, 1 to 100000.
screenshotfullPage (boolean, optional)Captures a PNG of the viewport, or of the whole page when fullPage is true. Defaults to false.
presskey (string, required)Presses a key, such as Enter, Tab, Escape or ArrowDown. 1 to 64 bytes.
executeJavascriptcode (string, required)Runs JavaScript in the page and returns its value in js_results. Up to 100000 bytes.

A request takes up to 50 actions, including the screenshot that screenshot: true adds, and all of them share a 45-second budget. A step that fails, such as a selector that never appears, is reported in the response and the next step still runs. Once the 45 seconds are spent, the remaining steps are skipped without running and reported as failed. Set screenshot: true to add a viewport screenshot at the end when your actions do not already take one.

Warning
mobile cannot be combined with actions or screenshots, and the query and attributes formats cannot be combined with actions or screenshots. Actions also cannot be combined with cookies or antibot: false. Each of these returns 400.

Example: click to reveal a phone number

Click the button that reveals the number, then wait for the element that holds it before extracting.

curl
curl -X POST https://api.webclaw.io/v1/scrape \
  -H "Authorization: Bearer wc_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/listing/123",
    "formats": ["markdown"],
    "actions": [
      { "type": "click", "selector": "button.show-phone" },
      { "type": "waitForSelector", "selector": ".phone-number", "timeout": 5000 }
    ]
  }'
Python
from webclaw import Webclaw

client = Webclaw("wc_your_api_key")
result = client.scrape(
    "https://example.com/listing/123",
    formats=["markdown"],
    actions=[
        {"type": "click", "selector": "button.show-phone"},
        {"type": "waitForSelector", "selector": ".phone-number", "timeout": 5000},
    ],
)
print(result.markdown)

Action results

actions_performed lists one entry per action, in order, with the action type, whether it succeeded and an error message when it did not. js_results holds the value of each executeJavascript step, or null when it failed. screenshot holds the last screenshot taken, as a data:image/png;base64 URL.

json
{
  "url": "https://example.com/listing/123",
  "metadata": { "title": "Listing 123", "word_count": 412 },
  "actions_performed": [
    { "action": "click", "success": true },
    { "action": "waitForSelector", "success": true }
  ],
  "markdown": "# Listing 123\n\nPhone: +1 555 0100\n..."
}

Response

The response includes the requested formats alongside extracted metadata. Only the formats you request are populated.

json
{
  "url": "https://example.com",
  "metadata": {
    "title": "Example Domain",
    "description": "This domain is for use in illustrative examples.",
    "author": null,
    "published_date": null,
    "language": "en",
    "site_name": "Example",
    "image": null,
    "favicon": "https://example.com/favicon.ico",
    "word_count": 1234
  },
  "markdown": "# Example Domain\n\nThis domain is for use in illustrative examples...",
  "text": "Example Domain\n\nThis domain is for use in illustrative examples...",
  "llm": "> URL: https://example.com\n> Title: Example Domain\n\nThis domain is for use in illustrative examples...\n\n## Links\n- ...",
  "extraction": { "metadata": { "title": "Example Domain", "word_count": 28 }, "content": { "markdown": "# Example Domain", "plain_text": "Example Domain", "links": [], "images": [], "code_blocks": [] } }
}

Metadata fields

FieldTypeDescription
titlestringPage title from OG, meta, or title tag.
descriptionstringPage description from meta or OG tags.
authorstring?Author name if detected.
published_datestring?Publication date if found in metadata.
languagestring?Page language code (e.g. "en").
site_namestring?Site name from OG metadata.
imagestring?Primary image URL (OG or Twitter Card).
faviconstring?Favicon URL.
word_countnumberTotal word count of extracted content.

Examples

Basic extraction

curl
curl -X POST https://api.webclaw.io/v1/scrape \
  -H "Authorization: Bearer wc_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://openai.com/blog/gpt-4",
    "formats": ["markdown"]
  }'

LLM-optimized with selector filtering

curl
curl -X POST https://api.webclaw.io/v1/scrape \
  -H "Authorization: Bearer wc_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://docs.stripe.com/payments/checkout",
    "formats": ["llm"],
    "include_selectors": [".content-container"],
    "exclude_selectors": ["nav", "footer", ".sidebar"],
    "only_main_content": true
  }'

Multiple output formats

curl
curl -X POST https://api.webclaw.io/v1/scrape \
  -H "Authorization: Bearer wc_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://en.wikipedia.org/wiki/Web_scraping",
    "formats": ["markdown", "llm", "text"]
  }'
Note
PDFs are auto-detected via Content-Type. If the URL serves a PDF, webclaw extracts text using its PDF engine instead of HTML parsing.

Error responses

400 Bad Request
{
  "error": "Missing required field: url"
}
401 Unauthorized
{
  "error": "invalid or missing API key"
}
503 Service Unavailable — query provider
{
  "error": "The page question could not be answered. Please retry later."
}

Related reading

Get started

Ready to build? Start extracting.

Cancel anytime. One key for every format and endpoint.

View on GitHub