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

# Langchain

> 用于 Lanchain 应用程序的网页抓取 API 节点

Decodo Node.js LangChain 插件使开发人员能够在其 LangChain 应用程序中使用 Decodo 的 Scraper API。

Decodo Lanchain 工具集成适用于 [**Web API Advanced 计划**](https://dashboard.decodo.com/register?page=scrapers/pricing?plan=907849)。

<Note>
  更多信息可以在 GitHub [这里](https://github.com/Decodo/decodo-langchain-ts)找到。
</Note>

## 功能

* 网页抓取：抓取任何 URL
* Google 搜索：搜索 Google 并检索结构化结果
* Amazon 搜索：搜索 Amazon 并检索结构化产品数据
* Reddit 抓取：抓取 Reddit 帖子和子版块
* 完整的 TypeScript 支持：所有参数的完整类型定义
* LangChain 集成：与 LangChain 的工具系统无缝集成

## 快速开始

### 先决条件

* Node.js >= v20

安装：

<CodeGroup>
  ```shellscript Shell theme={null}
  npm install @decodo/langchain-ts
  ```
</CodeGroup>

激活 Advanced 计划后，记下您生成的用户名和密码：

<Frame>
  <img src="https://mintcdn.com/decodo/HeowWjVaMvMCJRIK/images/docs/69973ef8dc4e19e425e9c875e9634279bb7073c999968317c45ebfeb948bd052-image.png?fit=max&auto=format&n=HeowWjVaMvMCJRIK&q=85&s=81a2bb174c7697b0bd6e50bfcdf03b66" style={{ width:"64%" }} className="mx-auto" width="697" height="322" data-path="images/docs/69973ef8dc4e19e425e9c875e9634279bb7073c999968317c45ebfeb948bd052-image.png" />
</Frame>

1. 克隆此仓库并安装依赖项

<CodeGroup>
  ```shellscript Shell theme={null}
  git clone [email protected]:Decodo/decodo-langchain-ts.git
  cd decodo-langchain-ts
  npm i
  ```
</CodeGroup>

2. 运行任何示例代理

<CodeGroup>
  ```shellscript Shell theme={null}
  npm run example:agent-universal
  npm run example:agent-google
  npm run example:agent-amazon
  ```
</CodeGroup>

一个简单的代理示例：

<CodeGroup>
  ```javascript Node expandable wrap theme={null}
  import dotenv from 'dotenv';
  import { ChatOpenAI } from '@langchain/openai';
  import { createReactAgent } from '@langchain/langgraph/prebuilt';
  import { DecodoUniversalTool } from '@decodo/langchain-ts';

  dotenv.config();

  const main = async () => {
    const username = process.env.SCRAPER_API_USERNAME!;
    const password = process.env.SCRAPER_API_PASSWORD!;

    const decodoUniversalTool = new DecodoUniversalTool({ username, password });

    const model = new ChatOpenAI({
      model: 'gpt-4o-mini',
    });

    const agent = createReactAgent({
      llm: model,
      tools: [decodoUniversalTool],
    });

    const result = await agent.invoke({
      messages: [
        {
          role: 'user',
          content: 'scrape the wikipedia NBA 2025 season page and tell me who won in 2025?',
        },
      ],
    });

    console.log(result.messages[result.messages.length - 1].content);
  };

  if (require.main === module) {
    main();
  }
  ```
</CodeGroup>

所有工具都接受一个 DecodoConfig 对象：

<CodeGroup>
  ```javascript Node theme={null}
  type DecodoConfig = {
    username: string; // 您的 Web Advanced 产品用户名
    password: string; // 您的 Web Advanced 产品密码
  };
  ```
</CodeGroup>

## 参数

**网页抓取：**

| 参数         | 必需 | 描述                                                                             |
| ---------- | -- | ------------------------------------------------------------------------------ |
| `url`      | ✅  | 网站 URL                                                                         |
| `geo`      |    | 结果所依赖的地理位置。[了解更多](https://help.decodo.com/docs/web-scraping-api-localisation)。 |
| `JsRender` |    | 设置为 `true` 时，启用 JavaScript 渲染                                                  |
| `markdown` |    | 设置为 `true` 时，返回 markdown 响应                                                    |

**Google 搜索：**

| 参数         | 必需 | 描述                                                                             |
| ---------- | -- | ------------------------------------------------------------------------------ |
| `query`    | ✅  | 搜索查询                                                                           |
| `parse`    |    | 设置为 `true` 时自动解析结果                                                             |
| `geo`      |    | 结果所依赖的地理位置。[了解更多](https://help.decodo.com/docs/web-scraping-api-localisation)。 |
| `JsRender` |    | 设置为 `true` 时，启用 JavaScript 渲染。                                                 |

**Amazon 搜索：**

| 参数         | 必需 | 描述                                                                                     |
| ---------- | -- | -------------------------------------------------------------------------------------- |
| `query`    | ✅  | 搜索查询                                                                                   |
| `parse`    |    | 设置为 `true` 时自动解析结果                                                                     |
| `geo`      |    | 结果所依赖的地理位置。[了解更多](https://help.decodo.com/docs/web-scraping-api-amazon-geo-parameter)。 |
| `JsRender` |    | 设置为 `true` 时，启用 JavaScript 渲染。                                                         |

**Reddit 抓取：**

| 参数      | 必需 | 描述                                                                            |
| ------- | -- | ----------------------------------------------------------------------------- |
| `url`   | ✅  | Reddit 子版块 URL                                                                |
| `geo`   |    | 结果所依赖的地理位置。[了解更多](https://help.decodo.com/docs/web-scraping-api-localisation) |
| `parse` |    | 设置为 `true` 时自动解析结果                                                            |

***

<Columns cols={2}>
  <Card title="支持" href="https://direct.lc.chat/12092754" cta="让我们聊聊！">
    需要帮助或只是想打个招呼？我们的支持团队全天候为您服务。 \
    您也可以随时通过电子邮件 [support@decodo.com](mailto:support@decodo.com) 联系我们。
  </Card>

  <Card title="反馈" href="mailto:feedback@decodo.com" cta="分享反馈">
    找不到您要找的内容？请求一篇文章！ \
    有反馈意见？分享您对我们如何改进的想法。
  </Card>
</Columns>
