Skip to main content
Nimble 的 Extract API 通过无头浏览器访问特定 URL 来提取其渲染后的内容。与发现内容的搜索 API 不同,Extract 工具处理已知 URL——非常适合需要获取和处理特定网页的智能体工作流,包括分页、过滤器和客户端渲染背后的内容。

概述

集成详情

可序列化JS 支持最新包版本
NimbleExtractToollangchain-nimblePyPI - Version

工具功能

返回工件原生异步返回数据定价
标题、URL、内容(markdown/plain_text/HTML)、元数据提供免费试用
主要特性:
  • URL 提取:并行提取 1-20 个 URL 的渲染内容
  • 动态渲染:处理 JavaScript、懒加载和客户端渲染
  • 多种格式:plain_text(默认)、markdown 或 simplified_html
  • 可配置等待时间:控制慢加载内容的页面加载行为
  • 浏览器驱动:可选 vx6、vx8 或 vx10 驱动以满足不同渲染需求
  • 生产就绪:原生异步支持、自动重试、连接池

设置

该集成位于 langchain-nimble 包中。
pip install -U langchain-nimble

凭证

您需要一个 Nimble API 密钥才能使用此工具。在 Nimble 注册以获取您的 API 密钥并访问免费试用。
import getpass
import os

if not os.environ.get("NIMBLE_API_KEY"):
    os.environ["NIMBLE_API_KEY"] = getpass.getpass("Nimble API key:\n")

实例化

现在我们可以实例化工具:
from langchain_nimble import NimbleExtractTool

# Basic usage
tool = NimbleExtractTool()

在智能体中使用

我们可以将 Nimble 提取工具与智能体结合使用,赋予其 URL 内容提取能力。以下是使用 LangGraph 的完整示例:
import os
import getpass

from langchain_nimble import NimbleExtractTool
from langchain.agents import create_agent
from langchain.chat_models import init_chat_model

if not os.environ.get("OPENAI_API_KEY"):
    os.environ["OPENAI_API_KEY"] = getpass.getpass("OpenAI API key:\n")
if not os.environ.get("NIMBLE_API_KEY"):
    os.environ["NIMBLE_API_KEY"] = getpass.getpass("Nimble API key:\n")

# Initialize Nimble Extract Tool
extract_tool = NimbleExtractTool(
    parsing_type="markdown"
)

# Create agent with the tool
model = init_chat_model(model="gpt-4o", model_provider="openai", temperature=0)
agent = create_agent(model, [extract_tool])

# Ask the agent to extract and analyze content from LangChain documentation
user_input = "Extract and summarize the key concepts from these LangChain docs: https://python.langchain.com/docs/concepts/retrievers/, https://python.langchain.com/docs/concepts/tools/"

for step in agent.stream(
    {"messages": user_input},
    stream_mode="values",
):
    step["messages"][-1].pretty_print()
================================ Human Message =================================

Extract and summarize the key concepts from these LangChain docs: https://python.langchain.com/docs/concepts/retrievers/, https://python.langchain.com/docs/concepts/tools/

================================== Ai Message ==================================
Tool Calls:
  nimble_extract (call_abc123)
 Call ID: call_abc123
  Args:
    links: ['https://python.langchain.com/docs/concepts/retrievers/', 'https://python.langchain.com/docs/concepts/tools/']
    parsing_type: markdown

================================= Tool Message =================================
Name: nimble_extract

[{"title": "Retrievers | LangChain", "url": "https://python.langchain.com/docs/concepts/retrievers/", "content": "# Retrievers\n\nA retriever is an interface that returns documents given an unstructured query...\n\n## Key Concepts\n- Document retrieval from various sources\n- Integration with vector stores...", "metadata": {"extracted_at": "2025-12-10T..."}}, {"title": "Tools | LangChain", "url": "https://python.langchain.com/docs/concepts/tools/", "content": "# Tools\n\nTools are interfaces that agents can use to interact with the world...", "metadata": {...}}]

================================== Ai Message ==================================

Based on the extracted LangChain documentation, here are the key concepts:

**Retrievers:**
- Interface for returning documents based on unstructured queries
- Supports various data sources including vector stores
- Core component for RAG (Retrieval Augmented Generation) applications
- Enables semantic search over document collections

**Tools:**
- Interfaces enabling agents to interact with external systems
- Can be used for web search, API calls, calculations, and more
- Agents use tools to extend their capabilities beyond text generation
- Support both synchronous and asynchronous execution

高级配置

该工具支持对 URL 提取进行广泛配置:
参数类型默认值描述
linkslist[str]None要提取的 URL(1-20 个)- 由智能体在运行时提供
parsing_typestr”plain_text”输出格式:“plain_text”、“markdown” 或 “simplified_html”
driverstr”vx6”浏览器驱动版本:“vx6”(快速)、“vx8”(均衡)或 “vx10”(全面)
waitintNone等待页面加载的毫秒数(0-60000)
renderboolTrue启用 JavaScript 渲染
localestr”en”页面区域偏好(如 “en-US”)
countrystr”US”本地化内容的国家代码(如 “US”)
api_keystrenv varNimble API 密钥(默认为 NIMBLE_API_KEY 环境变量)

最佳实践

驱动选择

  • vx6(默认):适用于标准网站的快速提取
  • vx8:适用于中等复杂度网站的均衡性能
  • vx10:适用于 JavaScript 密集型单页应用和复杂动态内容的全面渲染

何时使用等待时间

  • 不等待wait=None):最适合大多数具有快速初始渲染的现代网站
  • 短等待wait=1000-2000):适用于懒加载或动态内容的网站
  • 较长等待wait=5000+):适用于加载缓慢的页面或需要时间完整渲染的复杂单页应用

URL 管理

  • 批量提取:每次调用提供 1-20 个 URL 以并行提取
  • 错误处理:失败的 URL 将在智能体错误处理中报告
  • 内容验证:智能体应在处理前验证提取的内容

性能优化

  • 选择合适的格式:使用 plain_text 提高速度,使用 markdown 保留结构,使用 HTML 获取详细样式
  • 调整等待时间:仅在必要时使用等待时间,以平衡速度和可靠性
  • 批量处理相关 URL:并行提取同一域名下的多个 URL 以提高效率
  • 使用异步:并发提取多个 URL 时调用 ainvoke()

API 参考

有关所有 NimbleExtractTool 功能和配置的详细文档,请访问 Nimble API 文档