Spider 抓取器
SpiderTool
Section titled “SpiderTool”Spider 是最快
的开源抓取和爬取工具,可返回适合 LLM 使用的数据。
它可以把任意网站转换为纯 HTML、markdown、元数据或文本,同时还能借助 AI 执行自定义动作进行爬取。
要使用 SpiderTool,你需要同时安装 Spider SDK
和 crewai[tools] SDK:
pip install spider-client 'crewai[tools]'下面示例展示如何使用 SpiderTool 让你的智能体抓取和爬取网站。
Spider API 返回的数据已经适合 LLM 使用,因此无需额外清洗。
from crewai_tools import SpiderTool
def main(): spider_tool = SpiderTool()
searcher = Agent( role="Web Research Expert", goal="Find related information from specific URL's", backstory="An expert web researcher that uses the web extremely well", tools=[spider_tool], verbose=True, )
return_metadata = Task( description="Scrape https://spider.cloud with a limit of 1 and enable metadata", expected_output="Metadata and 10 word summary of spider.cloud", agent=searcher )
crew = Crew( agents=[searcher], tasks=[ return_metadata, ], verbose=2 )
crew.kickoff()
if __name__ == "__main__": main()| 参数 | 类型 | 描述 |
|---|---|---|
| api_key | string | 指定 Spider API key。如果未指定,则会从环境变量 SPIDER_API_KEY 中读取。 |
| params | object | 请求的可选参数。默认值为 {"return_format": "markdown"},以便优化面向 LLM 的内容。 |
| request | string | 要执行的请求类型(http、chrome、smart)。smart 默认使用 HTTP,必要时切换为 JavaScript 渲染。 |
| limit | int | 每个网站可爬取的最大页面数。设置为 0 或省略则表示无限制。 |
| depth | int | 最大爬取深度。设置为 0 表示不限制。 |
| cache | bool | 启用 HTTP 缓存以加快重复运行。默认值为 true。 |
| budget | object | 为爬取页面设置基于路径的限制,例如 {"*":1} 表示只抓取根页面。 |
| locale | string | 请求的语言环境,例如 en-US。 |
| cookies | string | 请求的 HTTP cookies。 |
| stealth | bool | 为 Chrome 请求启用隐身模式以避免被检测。默认值为 true。 |
| headers | object | 适用于所有请求的 HTTP 头部键值映射。 |
| metadata | bool | 存储页面和内容的元数据,帮助 AI 互操作。默认值为 false。 |
| viewport | object | 设置 Chrome 视口尺寸。默认值为 800x600。 |
| encoding | string | 指定编码类型,例如 UTF-8、SHIFT_JIS。 |
| subdomains | bool | 爬取中包含子域名。默认值为 false。 |
| user_agent | string | 自定义 HTTP user agent。默认使用随机 agent。 |
| store_data | bool | 启用请求的数据存储。如果设置则覆盖 storageless。默认值为 false。 |
| gpt_config | object | 允许 AI 生成爬取动作,并可通过数组为 "prompt" 提供链式步骤。 |
| fingerprint | bool | 为 Chrome 启用高级指纹识别。 |
| storageless | bool | 防止任何数据存储,包括 AI embeddings。默认值为 false。 |
| readability | bool | 使用 Mozilla 的 readability 对内容进行预处理,以改善 LLM 可读性。 |
| return_format | string | 返回数据的格式:markdown、raw、text、html2text。使用 raw 获取默认页面格式。 |
| proxy_enabled | bool | 启用高性能代理以避免网络层阻断。 |
| query_selector | string | 用于从标记中提取内容的 CSS 查询选择器。 |
| full_resources | bool | 下载网站链接的所有资源。 |
| request_timeout | int | 请求超时时间(秒,5-60)。默认值为 30。 |
| run_in_background | bool | 在后台运行请求,适用于数据存储和触发 dashboard 爬取。如果设置了 storageless,则无效。 |