网页内容抓取工具。使用 webfetch CLI 抓取网页并转换为 Markdown、文本或 HTML。触发场景:抓取网页、获取网页内容、网页转 Markdown、网页转文本、下载网页。
封装 webfetch 命令行工具,用于抓取网页内容并转换为多种格式。
当用户表达抓取网页、获取网页内容、网页转 Markdown 意图时,执行如下命令:
text
webfetch "https://example.com"
视需要也可以使用如下常见用法:
text
webfetch "https://example.com" # 默认输出 Markdown
webfetch "https://example.com" -f text # 输出纯文本
webfetch "https://example.com" -f html # 输出原始 HTML
webfetch "https://example.com" -o article.md # 保存到文件
webfetch "https://example.com" -q > output.md # 静默模式,适合管道
当网络环境需要代理时,有两种方式:
方式一:环境变量(推荐)
text
export HTTPS_PROXY=http://proxy:8080
webfetch "https://example.com"
方式二:命令行参数
text
webfetch "https://example.com" --proxy http://proxy:8080
当遇到 TLS 证书问题(如自签名证书)时:
text
webfetch "https://example.com" --insecure
当目标网站响应较慢时:
text
webfetch "https://example.com" --timeout 60
如果执行失败,按照以下步骤排查:
text
1. 检查安装 → 2. 检查网络 → 3. 检查代理配置
Step 1: 检查是否安装 webfetch
text
command -v webfetch
如果未安装,执行:
text
npm install -g @lyhue1991/webfetch
Step 2: 检查网络连接
text
curl -I https://example.com
Step 3: 检查代理配置
text
printenv HTTP_PROXY HTTPS_PROXY
如果需要代理但未配置:
text
webfetch "https://example.com" --proxy http://proxy:8080
Markdown 格式(默认)
text
webfetch "https://mp.weixin.qq.com/s/xxx" -o article.md
纯文本格式
text
webfetch "https://example.com" -f text
原始 HTML
text
webfetch "https://example.com" -f html
参数说明<url>目标 URL,必填-f, --format <format>输出格式:markdown(默认)、text、html-t, --timeout <seconds>超时时间(秒),最大 120,默认 30-o, --output <file>保存到指定文件-q, --quiet静默模式,仅输出内容--proxy <url>代理服务器地址--insecure跳过 TLS 证书验证
变量说明HTTP_PROXYHTTP 请求代理HTTPS_PROXYHTTPS 请求代理NO_PROXY跳过代理的主机列表
--insecure 参数代码说明0成功1用户错误(无效 URL、参数错误)2网络错误(超时、DNS 解析失败)3服务器错误(4xx、5xx 响应)
text
# 查看帮助
webfetch --help
# 查看版本
webfetch --version
# 基础抓取
webfetch "https://example.com"
# 输出纯文本
webfetch "https://example.com" -f text
# 保存到文件
webfetch "https://example.com" -o output.md
# 使用代理
webfetch "https://example.com" --proxy http://proxy:8080
# 跳过证书验证
webfetch "https://example.com" --insecure
# 自定义超时
webfetch "https://example.com" --timeout 60
# 静默模式(适合管道)
webfetch "https://example.com" -q > output.md