> 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/automate-zh/cao-zuo-zhi-nan/element/get-element-attribute.md).

# 获取元素属性

此操作帮助您“提取”网页元素内部的隐藏信息，并将其存储到变量中以供后用。

* 作用：例如，您可以从属性 `src` 中获取图片路径，或从链接标签的 `href` 属性中获取链接，或者获取输入框中的 `value` 值。
* 简单理解：网页上的每个组件都有一些随附的“属性”（就像信息标签）。此命令帮助您读取并“复制”该标签中的信息以进行保存。

#### 配置参数解释：

* 元素 XPath：包含需要提取属性的元素在网页界面的标识路径（XPath）。
* 属性名称：您想要提取数据的属性名称。
  * *示例结构*：`<标签 名称_属性="属性值">文本</标签>` ➔ 您只需在此框中填写 `名称_属性` 以提取 `属性值`。
* 输出变量：用于存储成功提取的属性值字符串的变量名称。

#### 实际示例：基于实际图片抓取产品图片链接（图 5）

根据您正在操作的手机商店网页界面，您希望抓取三星 Galaxy S6 手机的图片路径，以便于数据存储或自动上传到您的商店。

查看 HTML 源代码表（图右侧红框）：

> 图片标签结构：`<img class="card-img-top img-fluid" src="imgs/galaxy_s6.jpg" alt="">`

要获取图片路径字符串 `imgs/galaxy_s6.jpg`，您将配置操作如下：

* 元素 XPath：准确输入指向该图片标签的 XPath 路径，例如：`//div[@class="card h-100"]/a/img`（或使用您图中的语法：`//div[@class='card h-100']//img`）。
* 属性名称：填写 `src` *(这是包含图片文件路径的属性名称)*。
* 输出变量：将输出变量命名为 `imgUrl`。

结果：系统将找到三星 Galaxy S6 的图片标签，提取 `src` 属性中的字符串值，并将 `imgs/galaxy_s6.jpg` 的值直接加载到变量 `$imgUrl` 中。您可以使用此变量进行图片下载或在后端存储。


---

# 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/automate-zh/cao-zuo-zhi-nan/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.
