AgentQLLoader
AgentQL 的文档加载器使用 AgentQL 查询从任何网页中提取结构化数据。AgentQL 可以跨多种语言和网页使用,而不会随着时间的推移和更改而中断。
概述
AgentQLLoader需要以下两个参数:
url:要从中提取数据的网页的 URL。query:要执行的 AgentQL 查询。详细了解如何在文档中编写 AgentQL 查询或在 AgentQL Playground 中测试查询。
设置以下参数是可选的:
api_key:来自 dev.agentql.com 的 AgentQL API 密钥。Optional.timeout:在超时之前等待请求的秒数。默认为900.is_stealth_mode_enabled:是否启用实验性反 Bot 规避策略。此功能可能并非始终适用于所有网站。启用此模式后,数据提取可能需要更长的时间才能完成。默认为False.wait_for:在提取数据之前等待页面加载的秒数。默认为0.is_scroll_to_bottom_enabled:是否在提取数据之前滚动到页面底部。默认为False.mode:"standard"使用深度数据分析,而"fast"以一定的分析深度换取速度,对于大多数用例来说已经足够了。在本指南中了解有关模式的更多信息。 默认为"fast".is_screenshot_enabled:是否在提取数据之前进行截图。在 'metadata' 中作为 Base64 字符串返回。默认为False.
AgentQLLoader 是使用 AgentQL 的 REST API 实现的
集成详细信息
| 类 | 包 | 本地化 | 序列 化 | JS 支持 |
|---|---|---|---|---|
| AgentQLLoader | langchain-agentql | ✅ | ❌ | ❌ |
Loader 功能
| 源 | 文档延迟加载 | 原生异步支持 |
|---|---|---|
| AgentQLLoader | ✅ | ❌ |
设置
要使用 AgentQL Document Loader,您需要配置AGENTQL_API_KEY环境变量,或使用api_key参数。您可以从我们的开发人员门户获取 API 密钥。
安装
安装 langchain-agentql。
%pip install -qU langchain_agentql
设置凭据
import os
os.environ["AGENTQL_API_KEY"] = "YOUR_AGENTQL_API_KEY"
初始化
接下来实例化你的 Model 对象:
from langchain_agentql.document_loaders import AgentQLLoader
loader = AgentQLLoader(
url="https://www.agentql.com/blog",
query="""
{
posts[] {
title
url
date
author
}
}
""",
is_scroll_to_bottom_enabled=True,
)
负荷
docs = loader.load()
docs[0]
Document(metadata={'request_id': 'bdb9dbe7-8a7f-427f-bc16-839ccc02cae6', 'generated_query': None, 'screenshot': None}, page_content="{'posts': [{'title': 'Launch Week Recap—make the web AI-ready', 'url': 'https://www.agentql.com/blog/2024-launch-week-recap', 'date': 'Nov 18, 2024', 'author': 'Rachel-Lee Nabors'}, {'title': 'Accurate data extraction from PDFs and images with AgentQL', 'url': 'https://www.agentql.com/blog/accurate-data-extraction-pdfs-images', 'date': 'Feb 1, 2025', 'author': 'Rachel-Lee Nabors'}, {'title': 'Introducing Scheduled Scraping Workflows', 'url': 'https://www.agentql.com/blog/scheduling', 'date': 'Dec 2, 2024', 'author': 'Rachel-Lee Nabors'}, {'title': 'Updates to Our Pricing Model', 'url': 'https://www.agentql.com/blog/2024-pricing-update', 'date': 'Nov 19, 2024', 'author': 'Rachel-Lee Nabors'}, {'title': 'Get data from any page: AgentQL’s REST API Endpoint—Launch week day 5', 'url': 'https://www.agentql.com/blog/data-rest-api', 'date': 'Nov 15, 2024', 'author': 'Rachel-Lee Nabors'}]}")
print(docs[0].metadata)
{'request_id': 'bdb9dbe7-8a7f-427f-bc16-839ccc02cae6', 'generated_query': None, 'screenshot': None}
延迟加载
AgentQLLoader目前只加载一个Document一次。因此load()和lazy_load()行为相同:
pages = [doc for doc in loader.lazy_load()]
pages
[Document(metadata={'request_id': '06273abd-b2ef-4e15-b0ec-901cba7b4825', 'generated_query': None, 'screenshot': None}, page_content="{'posts': [{'title': 'Launch Week Recap—make the web AI-ready', 'url': 'https://www.agentql.com/blog/2024-launch-week-recap', 'date': 'Nov 18, 2024', 'author': 'Rachel-Lee Nabors'}, {'title': 'Accurate data extraction from PDFs and images with AgentQL', 'url': 'https://www.agentql.com/blog/accurate-data-extraction-pdfs-images', 'date': 'Feb 1, 2025', 'author': 'Rachel-Lee Nabors'}, {'title': 'Introducing Scheduled Scraping Workflows', 'url': 'https://www.agentql.com/blog/scheduling', 'date': 'Dec 2, 2024', 'author': 'Rachel-Lee Nabors'}, {'title': 'Updates to Our Pricing Model', 'url': 'https://www.agentql.com/blog/2024-pricing-update', 'date': 'Nov 19, 2024', 'author': 'Rachel-Lee Nabors'}, {'title': 'Get data from any page: AgentQL’s REST API Endpoint—Launch week day 5', 'url': 'https://www.agentql.com/blog/data-rest-api', 'date': 'Nov 15, 2024', 'author': 'Rachel-Lee Nabors'}]}")]
API 参考
有关如何使用此集成的更多信息,请参阅 git 存储库或 langchain 集成文档