Web-curl 是一款功能强大的工具,可用于从网页和 API 中获取并提取文本内容。你既可以将其作为独立的命令行工具使用,也能将其作为 MCP(模型上下文协议)服务器来运行。它借助 Puppeteer 实现强大的网页抓取功能,还支持资源阻塞、自定义请求头、身份验证以及谷歌自定义搜索等高级特性。
# 克隆仓库
git clone
cd web-curl
# 安装依赖
npm install
# 构建项目
npm run build
npm install 即可。sudo apt-get install -y \
ca-certificates fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 \
libatk1.0-0 libcups2 libdbus-1-3 libdrm2 libgbm1 libnspr4 libnss3 \
libx11-xcb1 libxcomposite1 libxdamage1 libxrandr2 xdg-utils
更多详细信息,请参阅 Puppeteer 故障排除指南。CLI 支持从网页中获取并提取文本内容。
# 基本用法
node build/index.js https://example.com
# 带选项使用
node build/index.js --timeout 30000 --no-block-resources https://example.com
# 将输出保存到文件
node build/index.js -o result.json https://example.com
--timeout :设置导航超时时间(默认值:60000)--no-block-resources:禁用对图片、样式表和字体的阻塞-o :将结果输出到指定文件Web-curl 可以作为 MCP 服务器运行,以便与 Roo Code 或其他支持 MCP 的平台集成。
npm run start
服务器通过标准输入输出进行通信,并公开了在 中定义的工具。
{
"name": "fetch_webpage",
"arguments": {
"url": "https://example.com",
"blockResources": true,
"timeout": 60000,
"maxLength": 10000
}
}
为谷歌自定义搜索设置以下环境变量:
APIKEY_GOOGLE_SEARCH:你的谷歌 API 密钥CX_GOOGLE_SEARCH:你的自定义搜索引擎 IDfetch_webpage、fetch_api、google_search 和 smart_command 等工具。git clone
cd web-curl
npm install
npm run build
node build/index.js https://example.com
{
"name": "fetch_webpage",
"arguments": {
"url": "https://example.com",
"blockResources": true,
"timeout": 60000,
"maxLength": 10000
}
}
node build/index.js --timeout 30000 --no-block-resources https://example.com
{
"name": "fetch_api",
"arguments": {
"url": "https://api.github.com/repos/nodejs/node",
"method": "GET",
"headers": {
"Accept": "application/vnd.github.v3+json"
}
}
}
{
"name": "google_search",
"arguments": {
"query": "web scraping best practices",
"num": 5
}
}
谷歌自定义搜索 API 是免费的,但有使用限制(例如,免费用户每天可进行 100 次查询,额外查询需要付费)。有关配额、定价和限制的完整详细信息,请参阅 官方文档。
YOUR_GOOGLE_API_KEY 和 YOUR_CX_ID 替换为你自己的值。timeout 参数的值。resourceTypesToBlock。APIKEY_GOOGLE_SEARCH 和 CX_GOOGLE_SEARCH。logs/error-log.txt 文件以获取详细的错误信息。maxLength 和 startIndex 对内容提取进行分页。欢迎贡献代码!如果你想贡献代码,请 Fork 此仓库并提交 Pull Request。
如果你发现任何问题或有建议,请在仓库页面上提交 Issue。
本项目由 Rayss 开发。
如有问题、改进建议或贡献代码,请联系作者或在仓库中提交 Issue。
演示视频 (MP4)
⚠️ 重要提示
谷歌搜索 API 是免费的,但有使用限制。详情请参阅:谷歌自定义搜索 API 概述
由 Rayss 开发
🚀 开源项目
🛠️ 使用 Node.js 和 TypeScript 构建(需要 Node.js v18+)