跳到主要內容
Open In ColabOpen on GitHub

AgentQLLoader

AgentQL 的文件載入器使用 AgentQL 查詢,提供從任何網頁提取結構化資料的功能。AgentQL 可跨多種語言和網頁使用,不會隨著時間和變更而失效。

概觀

AgentQLLoader 需要以下兩個參數

以下參數設定為選填

  • api_key:您的 AgentQL API 金鑰,可從 dev.agentql.com 取得。選填
  • timeout:請求逾時前等待的秒數。預設為 900
  • is_stealth_mode_enabled:是否啟用實驗性反機器人規避策略。此功能可能不適用於所有網站的所有時間。啟用此模式後,資料提取可能需要更長的時間才能完成。預設為 False
  • wait_for:提取資料前等待頁面載入的秒數。預設為 0
  • is_scroll_to_bottom_enabled:是否在提取資料前捲動到頁面底部。預設為 False
  • mode"standard" 使用深度資料分析,而 "fast" 則以速度換取部分分析深度,且足以應付大多數使用案例。在此指南中深入瞭解模式。 預設為 "fast"
  • is_screenshot_enabled:是否在提取資料前擷取螢幕截圖。以 Base64 字串形式在「metadata」中傳回。預設為 False

AgentQLLoader 是使用 AgentQL 的 REST API 實作

整合詳細資訊

類別套件本機可序列化JS 支援
AgentQLLoaderlangchain-agentql

載入器功能

來源文件延遲載入原生非同步支援
AgentQLLoader

設定

若要使用 AgentQL 文件載入器,您需要設定 AGENTQL_API_KEY 環境變數,或使用 api_key 參數。您可以從我們的 開發人員入口網站 取得 API 金鑰。

安裝

安裝 langchain-agentql

%pip install -qU langchain_agentql

設定憑證

import os

os.environ["AGENTQL_API_KEY"] = "YOUR_AGENTQL_API_KEY"

初始化

接下來,例項化您的模型物件

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 repolangchain 整合文件


此頁面是否對您有幫助?