For the complete documentation index, see llms.txt. This page is also available as Markdown.

Capture Element

Type: capture_element

Returns the outerHTML of the element matching your selector, the element itself, and everything inside it. Use it when you need an element's contents, rather than the entire page.

Tips for using capture_element action
  • Use this instead of capture_dom when you know where the content is. Pointing at main or article cuts out navigation and footers for you.

  • You don't need a wait first. This action already waits for its own selector, up to 5 seconds by default, and you can change that with timeout.

  • The action captures as soon as the element appears, so a longer timeout doesn't slow anything down. It's a ceiling, not a delay.

  • Increase the timeout for pages that load content after the initial render, so the action doesn't give up before the element exists.

  • It returns the element and everything inside it, including its opening and closing tags.

  • If your selector matches more than one element, only the first is captured.

Parameters

Name
Type
Required
Description

selector

string

The selector that defines the element whose contents you want to capture.

timeout

integer

The maximum amount of time the browser should wait for the element defined by the selector to appear. Default: 5000 (5s)

See universal parameters.

Usage

The following code will wait 1 second for the .page_contents element to appear and return an HTML file containing the div's innerHTML.

"actions": [
    {
      "type": "capture_element",
      "selector": ".page_contents",
      "timeout": 1000
    }
]

FAQs

When do I use the capture_element action?

Use it when you want the HTML for a specific part of a page and already know its selector: a results list, an article body, or a product panel. It's smaller and cleaner than capturing the whole DOM.

What does the capture_element action return?

It returns the matched element as an HTML file, including the element's own opening and closing tags. Capturing a table gives you the complete <table> element, not just its contents.

How long does capture_element wait for the element?

Up to five seconds by default, configurable with timeout in milliseconds. It captures as soon as the element appears, so increasing the timeout incurs no cost on pages where the element is already present.

Do I need a wait action before capture_element?

No. It already waits for its selector using timeout. Adding a separate wait on the same element just slows the request.

What happens if my selector doesn't match anything?

The action fails once the timeout is reached, and by default that stops the request. Set continue_on_fail: true if the element is optional, and use capture_dom to check what the selector should be.

When should I use generate_markdown instead of capture_element?

Use generate_markdown with a selector when you want that part of the page as readable text. Use capture_element when you need the HTML exactly as it is, with the tags and attributes intact.

What happens if my selector matches more than one element?

Only the first match is captured. To get several elements, select a shared container instead, or add a separate capture_element action for each one.

Last updated