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

> Web Scraping API node for Lanchain applications

A Decodo Node.js LangChain plugin that enables developers to use Decodo's Scraper API alongside their LangChain applications.

Decodo Lanchain Tool integration is available with any [**Web Scraping API plan**](https://dashboard.decodo.com/register?page=scrapers/pricing?plan=907849)**.**

<Note>
  More information can be found on GitHub [here](https://github.com/Decodo/decodo-langchain-ts).
</Note>

## Features

* Web Scraping: Scrape any URL
* Google Search: Search Google and retrieve structured results
* Amazon Search: Search Amazon and retrieve structured product data
* Reddit Scraping: Scrape Reddit posts and subreddits
* Full TypeScript Support: Complete type definitions for all parameters
* LangChain Integration: Seamless integration with LangChain's Tool system

## Quick start

### Prerequisites

* Node.js >= v20

Installation:

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

Once you have an Advanced plan activated, take a note of your generated username and password:

<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. Clone this repo and install dependencies

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

2. Run any of the sample agents

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

A simple agentic example:

<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>

All tools accept a DecodoConfig object:

<CodeGroup>
  ```javascript Node theme={null}
  type DecodoConfig = {
    username: string; // Your Web Advanced product username
    password: string; // Your Web Advanced product password
  };
  ```
</CodeGroup>

## Parameters

**Web Scraping:**

| Parameter  | Required | Description                                                                                                                     |
| ---------- | -------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `url`      | ✅        | Website URL                                                                                                                     |
| `geo`      |          | The geographical location on which the result depends. [Read more](https://help.decodo.com/docs/web-scraping-api-localisation). |
| `JsRender` |          | When set to `true`, enables javascript rendering                                                                                |
| `markdown` |          | When set to `true`, returns markdown response                                                                                   |

**Google Search:**

| Parameter  | Required | Description                                                                                                                     |
| ---------- | -------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `query`    | ✅        | Search query                                                                                                                    |
| `parse`    |          | Automatically parses results when set to `true`                                                                                 |
| `geo`      |          | The geographical location on which the result depends. [Read more](https://help.decodo.com/docs/web-scraping-api-localisation). |
| `JsRender` |          | When set to `true`, enables javascript rendering.                                                                               |

**Amazon Search:**

| Parameter  | Required | Description                                                                                                                             |
| ---------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| `query`    | ✅        | Search query                                                                                                                            |
| `parse`    |          | Automatically parses results when set to `true`                                                                                         |
| `geo`      |          | The geographical location on which the result depends. [Read more](https://help.decodo.com/docs/web-scraping-api-amazon-geo-parameter). |
| `JsRender` |          | When set to `true`, enables javascript rendering.                                                                                       |

**Reddit Scraping:**

| Parameter | Required | Description                                                                                                                    |
| --------- | -------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `url`     | ✅        | Reddit subreddit URL                                                                                                           |
| `geo`     |          | The geographical location on which the result depends. [Read more](https://help.decodo.com/docs/web-scraping-api-localisation) |
| `parse`   |          | Automatically parses results when set to `true`                                                                                |

***

<Columns cols={2}>
  <Card title="Support" href="https://direct.lc.chat/12092754" cta="Let's chat!">
    Need help or just want to say hello? Our support is available 24/7. \
    You can also reach us anytime via email at [support@decodo.com](mailto:support@decodo.com).
  </Card>

  <Card title="Feedback" href="mailto:feedback@decodo.com" cta="Share feedback">
    Can't find what you're looking for? Request an article! \
    Have feedback? Share your thoughts on how we can improve.
  </Card>
</Columns>
