web-fetch

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Web Fetch Skill

Web Fetch 技能

Fetch web content. Prefer the built-in WebFetch tool — it uses a real browser engine for JavaScript-rendered pages with high success rate. Fall back to curl only if WebFetch is unavailable.
获取网页内容。优先使用内置的WebFetch工具——它使用真实浏览器引擎处理JavaScript渲染的页面,成功率高。仅当WebFetch不可用时,才退而使用curl。

Fetch a Web Page (HTML → Text)

获取网页内容(HTML → 文本)

bash
undefined
bash
undefined

Get page content, strip HTML tags, first 500 lines

获取页面内容,去除HTML标签,取前500行

curl -sL "URL" | sed 's/<[^>]*>//g' | sed '/^$/d' | head -500
curl -sL "URL" | sed 's/<[^>]*>//g' | sed '/^$/d' | head -500

Or use lynx for better text extraction (if installed)

或者使用lynx进行更优的文本提取(需已安装)

lynx -dump -nolist "URL" | head -500
lynx -dump -nolist "URL" | head -500

Or use w3m

或者使用w3m

w3m -dump "URL" | head -500
undefined
w3m -dump "URL" | head -500
undefined

Fetch JSON API

获取JSON API内容

bash
curl -s "https://api.example.com/data" | jq '.'
bash
curl -s "https://api.example.com/data" | jq '.'

Fetch with Headers

携带请求头获取内容

bash
undefined
bash
undefined

With custom headers

携带自定义请求头

curl -s -H "Authorization: Bearer TOKEN" -H "Accept: application/json" "URL"
curl -s -H "Authorization: Bearer TOKEN" -H "Accept: application/json" "URL"

With user agent

携带用户代理

curl -sL -A "Mozilla/5.0" "URL"
undefined
curl -sL -A "Mozilla/5.0" "URL"
undefined

Download Files

下载文件

bash
undefined
bash
undefined

Download to specific path

下载到指定路径

curl -sL -o /tmp/file.pdf "URL"
curl -sL -o /tmp/file.pdf "URL"

Download with original filename

以原始文件名下载

curl -sLOJ "URL"
undefined
curl -sLOJ "URL"
undefined

Check URL Status

检查URL状态

bash
undefined
bash
undefined

Just get HTTP status code

仅获取HTTP状态码

curl -sL -o /dev/null -w "%{http_code}" "URL"
curl -sL -o /dev/null -w "%{http_code}" "URL"

Get headers only

仅获取响应头

curl -sI "URL"
undefined
curl -sI "URL"
undefined

Tips

小贴士

  • Use
    -sL
    for silent mode + follow redirects
  • Pipe to
    head -N
    to limit output and avoid context overflow
  • For large pages, extract just what you need with
    grep
    or
    sed
  • Use
    jq
    for JSON responses
  • Some sites block curl — add a browser User-Agent with
    -A
  • 使用
    -sL
    参数启用静默模式并跟随重定向
  • 通过管道传递给
    head -N
    来限制输出,避免内容溢出
  • 对于大页面,使用
    grep
    sed
    仅提取所需内容
  • 使用
    jq
    处理JSON响应
  • 部分网站会拦截curl请求——使用
    -A
    参数添加浏览器用户代理