> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bringits.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Attributes

> Extract attributes from DOM elements for detailed scraping operations

The Get Attributes command (GetAttributesCommand) enables you to extract attributes from DOM elements for detailed scraping operations. This command is essential for extracting links, images, data attributes, and other element attributes from web pages.

## Overview

The Get Attributes command provides functionality for:

* Extracting attributes from DOM elements
* Using CSS selectors to target elements
* Extracting multiple attributes at once
* Filtering elements by various criteria
* Returning structured attribute data

## Parameters

| Parameter           | Type   | Description                               | Required |
| ------------------- | ------ | ----------------------------------------- | -------- |
| **elementsLocator** | object | Element locator configuration             | Yes      |
| **attributes**      | array  | List of attributes to extract             | Yes      |
| **sessionId**       | string | Browser session identifier                | No       |
| **key**             | string | Key name for storing extracted attributes | Yes      |

## Element Locator Configuration

The `elementsLocator` object configures how elements are targeted:

```json theme={null}
{
  "elementsLocator": {
    "selector": "a.article-link",
    "timeout": 10000
  }
}
```

### Locator Properties

| Property     | Type   | Description                        | Required |
| ------------ | ------ | ---------------------------------- | -------- |
| **selector** | string | CSS selector for element targeting | Yes      |
| **timeout**  | number | Maximum wait time in milliseconds  | No       |
| **filter**   | object | Filter criteria                    | No       |

## Usage Examples

### Extract Link Attributes

```json theme={null}
{
  "command": "GetAttributes",
  "params": {
    "elementsLocator": {
      "selector": "a.article-link",
      "timeout": 10000
    },
    "attributes": ["href", "title"],
    "key": "article_links"
  }
}
```

### Extract Image Attributes

```json theme={null}
{
  "command": "GetAttributes",
  "params": {
    "elementsLocator": {
      "selector": "img.article-image",
      "timeout": 10000
    },
    "attributes": ["src", "alt", "width", "height"],
    "key": "article_images"
  }
}
```

### Extract Data Attributes

```json theme={null}
{
  "command": "GetAttributes",
  "params": {
    "elementsLocator": {
      "selector": "[data-item]",
      "timeout": 10000
    },
    "attributes": ["data-item-id", "data-item-type", "data-item-value"],
    "key": "item_data"
  }
}
```

### Extract with Session

```json theme={null}
{
  "command": "GetAttributes",
  "params": {
    "sessionId": "#{UUID}",
    "elementsLocator": {
      "selector": "a.link",
      "timeout": 10000
    },
    "attributes": ["href", "title", "class"],
    "key": "links"
  }
}
```

## Common Attributes

### Link Attributes

* **href**: Link destination URL
* **title**: Link title/tooltip
* **target**: Link target (\_blank, \_self, etc.)
* **rel**: Link relationship

### Image Attributes

* **src**: Image source URL
* **alt**: Alternative text
* **width**: Image width
* **height**: Image height
* **title**: Image title

### Data Attributes

* **data-**\*: Custom data attributes
* **id**: Element ID
* **class**: Element classes
* **aria-**\*: Accessibility attributes

## Output Structure

The command stores extracted attributes under the specified key:

### Single Element

```json theme={null}
{
  "article_link": {
    "href": "https://example.com/article",
    "title": "Article Title"
  }
}
```

### Multiple Elements

```json theme={null}
{
  "article_links": [
    {
      "href": "https://example.com/article1",
      "title": "Article 1"
    },
    {
      "href": "https://example.com/article2",
      "title": "Article 2"
    }
  ]
}
```

## Variable Support

The Get Attributes command supports variable interpolation in:

* **Selector**: Use variables in CSS selectors
* **Session ID**: Use `#{UUID}` for session tracking

## Best Practices

* **Use Stable Selectors**: Prefer class names and IDs over text-based selectors
* **Set Appropriate Timeouts**: Configure timeouts for dynamic content loading
* **Extract Relevant Attributes**: Only extract attributes you need
* **Handle Missing Attributes**: Account for cases where attributes don't exist
* **Use Descriptive Keys**: Use clear, descriptive key names for extracted attributes

## Common Use Cases

* **Link Extraction**: Extract links from pages
* **Image Extraction**: Extract image sources and metadata
* **Data Attribute Extraction**: Extract custom data attributes
* **Metadata Extraction**: Extract element metadata

## Related Commands

* [Browser Open](/stream/commands/browser/browser-open) - Open browser before extraction
* [Get Text Contents](/stream/commands/browser/get-text-contents) - Extract text instead of attributes
* [HTTP Request](/stream/commands/http/http-request) - Fetch resources from extracted URLs
