> For the complete documentation index, see [llms.txt](https://docs.gpmautomate.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gpmautomate.com/huong-dan-cac-action/element/get-element-attribute.md).

# Get element attribute

Hành động này giúp bạn "bóc tách" những thông tin ẩn bên trong một phần tử trên trang web và lưu nó vào một biến để dùng sau.

* Tác dụng: Ví dụ, bạn có thể lấy đường dẫn ảnh từ thuộc tính `src`, hoặc lấy link từ thuộc tính `href` của một thẻ liên kết, hay lấy giá trị nhập trong ô `value`.
* Cách hiểu đơn giản: Mỗi thành phần trên web đều có những "thuộc tính" đi kèm (như cái nhãn dán thông tin). Lệnh này giúp bạn đọc và "chép" thông tin từ cái nhãn đó ra để lưu lại.

#### Giải thích các tham số cấu hình:

* Element XPath: Đường dẫn mã định danh (XPath) của phần tử chứa thuộc tính cần lấy trên giao diện trang web.
* Attribute name: Tên của thuộc tính mà bạn muốn bốc tách dữ liệu.
  * *Ví dụ cấu trúc*: `<thẻ tên_thuộc_tính="giá_trị_thuộc_tính">Văn bản</thẻ>` ➔ Bạn chỉ cần điền `tên_thuộc_tính` vào ô này để lấy ra `giá_trị_thuộc_tính`.
* Output variable: Tên biến số để lưu lại chuỗi giá trị thuộc tính sau khi lấy thành công.

#### Ví dụ thực tế: Cào link ảnh sản phẩm dựa trên hình ảnh thực tế (Hình 5)

Dựa trên giao diện trang web cửa hàng điện thoại mà bạn đang thao tác trong hình, bạn muốn cào (scrape) đường dẫn hình ảnh của chiếc điện thoại Samsung galaxy s6 để phục vụ cho việc lưu trữ dữ liệu hoặc đăng tải tự động lên shop của mình.

Nhìn vào bảng mã nguồn HTML (khung đỏ bên phải hình):

> Cấu trúc thẻ ảnh: `<img class="card-img-top img-fluid" src="imgs/galaxy_s6.jpg" alt="">`

Để lấy được chuỗi đường dẫn ảnh `imgs/galaxy_s6.jpg`, bạn sẽ cấu hình hành động như sau:

* Element XPath: Nhập chính xác đường dẫn XPath đang chỉ vào thẻ ảnh đó, ví dụ: `//div[@class="card h-100"]/a/img` (hoặc dùng cú pháp như trong hình của bạn: `//div[@class='card h-100']//img`).
* Attribute name: Điền chữ `src` *(Đây là tên thuộc tính chứa đường dẫn tệp tin của hình ảnh)*.
* Output variable: Đặt tên biến đầu ra là `imgUrl`.

Kết quả: Hệ thống sẽ tìm đến thẻ ảnh của Samsung Galaxy S6, bóc tách chuỗi giá trị nằm trong thuộc tính `src` và nạp thẳng giá trị `imgs/galaxy_s6.jpg` vào biến `$imgUrl`. Bạn có thể sử dụng biến này cho các hành động tải ảnh hoặc lưu trữ ở phía sau.

<figure><img src="/files/KdV4rIjudLTjm6BvKDfR" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/MBDq9OrIWQKAhFjPj1a3" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.gpmautomate.com/huong-dan-cac-action/element/get-element-attribute.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
