@lyhue1991/webfetch
v0.1.0
Published
Fetch and convert web content to markdown, text, or html from the command line
Maintainers
Readme
webfetch
网页内容抓取工具,支持将网页转换为 Markdown、文本或 HTML 格式。可作为 CLI 工具或 OpenCode SKILL 使用。
安装
方式一:作为 SKILL 安装(推荐)
npx skills add lyhue1991/webfetch方式二:作为 CLI 工具安装
# 使用 npx 直接运行
npx @lyhue1991/webfetch https://example.com
# 或全局安装
npm install -g @lyhue1991/webfetch
webfetch https://example.com使用方法
webfetch <url> [options]参数说明
| 参数 | 简写 | 说明 | 默认值 |
|------|------|------|--------|
| --format | -f | 输出格式:markdown, text, html | markdown |
| --timeout | -t | 超时时间(秒),最大 120 | 30 |
| --output | -o | 保存到指定文件 | - |
| --quiet | -q | 静默模式,仅输出内容 | false |
| --proxy | | 代理服务器地址 | - |
| --insecure | | 跳过 TLS 证书验证 | false |
| --help | -h | 显示帮助 | - |
| --version | -v | 显示版本 | - |
示例
# 抓取并转换为 Markdown(默认)
webfetch https://example.com
# 输出纯文本
webfetch https://example.com -f text
# 保存到文件
webfetch https://example.com -o output.md
# 静默模式(适合管道)
webfetch https://example.com -q > content.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代理支持
webfetch 自动读取环境变量代理配置:
HTTP_PROXY/http_proxy- HTTP 请求代理HTTPS_PROXY/https_proxy- HTTPS 请求代理NO_PROXY/no_proxy- 跳过代理的主机列表
# 通过环境变量设置代理
export HTTPS_PROXY=http://proxy.example.com:8080
webfetch https://example.com
# 命令行覆盖代理
webfetch https://example.com --proxy http://custom-proxy:8080
# 禁用本次请求的代理
webfetch https://example.com --proxy ""
# 处理代理证书问题
webfetch https://example.com --insecure功能特性
- 多格式输出 - 转换 HTML 为 Markdown(默认)、纯文本或保留原始 HTML
- 智能内容处理 - 自动检测 Content-Type,正确处理非 HTML 响应
- 反爬虫策略 - Chrome UA 伪装,Cloudflare 挑战自动重试
- 安全限制 - 最大 5MB 响应限制,可配置超时
- 清洁输出 - 移除 script、style 等非内容元素
- 代理支持 - 自动环境变量检测,支持手动覆盖
退出码
| 代码 | 说明 | |------|------| | 0 | 成功 | | 1 | 用户错误(无效 URL、参数错误) | | 2 | 网络错误(超时、DNS 解析失败) | | 3 | 服务器错误(4xx、5xx 响应) |
系统要求
- Node.js >= 18.0.0
许可证
MIT
