@seepine/webfetch
v0.1.1
Published
A CLI tool to fetch web pages and convert them to markdown, text, or html
Maintainers
Readme
webfetch
抓取网页并转换为 Markdown / 纯文本 / HTML 的 CLI 工具。
功能特性
- 多格式输出 — 一键转换为 Markdown(默认)、纯文本或保留原始 HTML
- 快速抓取 — JSON / XML / Markdown 响应直接使用 Node fetch 返回原文,无需启动无头浏览器
- JavaScript 渲染 — 基于无头浏览器,支持 SPA、懒加载、动态渲染页面
- 智能内容提取 — 自动选取页面主体内容:
main>article>#content>.content>body - 清洁输出 — 移除 script、style、noscript、iframe 及图片引用等非内容元素
- 代理支持 — 自动读取环境变量代理配置,支持
--proxy手动指定 - 灵活超时 — 超时时间可配置(最大 120 秒),适配慢速站点
- TLS 容错 — 可跳过证书校验,应对自签名证书场景
安装
A. agent skill
本仓库提供 skills/webfetch/SKILL.md,封装了 webfetch 的命令行用法,可直接用于 Claude Code、OpenCode、Cursor 等 AI 编程工具,方便 AI 代理抓取网页、网页转 Markdown 等场景。
npx -y skills add https://github.com/seepine/webfetch -g -yB. cli
npm install -g @seepine/webfetch要求 Node.js >= 22.12(由 puppeteer / commander 的最低版本决定)。
使用方法
webfetch <url> [options]参数说明
| 参数 | 简写 | 说明 | 默认值 |
| ------------ | ---- | --------------------------------------------- | ---------- |
| --format | -f | 输出格式:markdown、text、html | markdown |
| --timeout | -t | 超时时间(秒),最大 120 | 30 |
| --output | -o | 保存到指定文件(无扩展名时自动补 .md) | - |
| --proxy | | 代理服务器地址(优先级最高) | - |
| --insecure | | 跳过 TLS 证书验证 | false |
| --help | -h | 显示帮助 | - |
| --version | -V | 显示版本 | - |
示例
# 抓取并转换为 Markdown(默认)
webfetch "https://example.com"
# 输出纯文本
webfetch "https://example.com" -f text
# 输出原始 HTML
webfetch "https://example.com" -f html
# 保存到文件
webfetch "https://example.com" -o output.md
# 自定义超时
webfetch "https://example.com" --timeout 60
# 使用代理
webfetch "https://example.com" --proxy http://proxy:8080
# 跳过证书验证(自签名证书场景)
webfetch "https://example.com" --insecure
# 抓取文章并保存
webfetch "https://example.com/article" -o article.md代理配置
当网络环境需要代理时,有两种方式:
方式一:环境变量(推荐)
export HTTPS_PROXY=http://proxy:8080
webfetch "https://example.com"方式二:命令行参数(优先级最高)
webfetch "https://example.com" --proxy http://proxy:8080环境变量
| 变量 | 说明 |
| ------------- | ------------------ |
| HTTP_PROXY | HTTP 请求代理 |
| HTTPS_PROXY | HTTPS 请求代理 |
| NO_PROXY | 跳过代理的主机列表 |
开发
pnpm cli # 直接运行 CLI(tsx 执行 TypeScript)
pnpm build # 构建发布版本(tsdown + chmod)
pnpm check # 格式检查 + 类型检查
pnpm tsc # 类型检查(不生成文件)
pnpm format # 使用 Prettier 格式化代码许可证
MIT
