Skip to content
CrewAI 文档版本 跟随上游 源快照 d0646a8e 更新于 2026-10-18

抓取网站

ScrapeWebsiteTool 旨在提取并读取指定网站的内容。

ScrapeWebsiteTool

NOTE

我们仍在改进这些工具,因此未来可能会出现意外行为或变更。

描述

一个旨在提取并读取指定网站内容的工具。它能够通过发起 HTTP 请求并解析收到的 HTML 内容来处理各种类型的网页。 该工具对网页抓取任务、数据收集或从网站中提取特定信息尤为有用。

抓取请求会经过 CrewAI 的 SSRF 安全 HTTP 辅助程序:请求的 URL 以及每一次重定向跳转都会对照私有地址与保留地址范围(包括云元数据)进行检查,并且 TCP 连接会被固定到通过该检查的 IP 上。

安装

安装 crewai_tools 包

shell
pip install 'crewai[tools]'

示例

python
from crewai_tools import ScrapeWebsiteTool

# To enable scrapping any website it finds during it's execution
tool = ScrapeWebsiteTool()

# Initialize the tool with the website URL, 
# so the agent can only scrap the content of the specified website
tool = ScrapeWebsiteTool(website_url='https://www.example.com')

# Extract the text from the site
text = tool.run()
print(text)

参数

参数类型描述
website_urlstring必填 要读取文件的网站 URL。这是该工具的主要输入,用于指定应抓取并读取哪个网站的内容。

BytesRouter 是社区翻译站点,所有译文仅供参考,一切以官方英文原文为准。