> 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-text.md).

# 获取元素文本

此操作帮助工具“读取”并提取一个元素上显示的所有文本（如文章内容、标题、价格或账户名称），然后将其保存到一个变量中以供您使用。

* 作用：当您需要从网站抓取文本数据时使用。您只需指定正确的位置（元素），工具将自动提取界面上显示的文本部分。

#### 配置参数解释：

* XPath：包含要提取的文本段落的元素的标识路径（XPath）。
* 输出变量：用于保存成功提取后的文本内容的变量名称。

#### 实际示例：抓取产品价格

根据您提供的商店界面图像，您希望抓取三星 Galaxy S6 手机的价格，以便进行价格比较或将数据同步到您的系统中。

查看右侧图像中红框标记的 HTML 源代码表：

> 包含价格的标签结构：`<h5>$360</h5>`

要获取文本字符串价格 `$360`，您将配置操作如下：

* 元素 XPath：准确输入指向该产品价格标签的 XPath 路径，例如：`//div[@class='card h-100']//h5`（如您在图中成功检查的 XPath 搜索框）。
* 输出变量：将输出变量命名为 `productPrice`。

结果：系统将找到对应产品的 `<h5>` 标签，提取标签中间的纯文本，并将值 `$360` 直接加载到变量 `$productPrice` 中。在后续步骤中，您可以调用此变量以写入 Excel 文件或上传到系统数据中。


---

# 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-text.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.
