http-response-handling
它能做什么
这项技能说明如何用类似浏览器的请求下载网页,并识别网站返回的空白占位页。适合从用 JavaScript 加载内容的网站收集信息的人。
适用场景
- ✓当网页因内容由 JavaScript 加载而只返回很少文字时。
- ✓当网站对简单的自动化请求返回不同内容时。
- ✓当我需要确认下载的网页是否真的包含所需信息时。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/http-response-handling/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我:我想读的网站在 AI 看来是空白页。请用类似浏览器的方式下载,并告诉我内容是否真的存在。”
每周 5 个新技能,1 分钟读完。
工作原理
AI 用 curl 加上类似浏览器的请求头下载网页,然后检查文件大小,并查找加载提示、转圈动画或 noscript 标签等标记,以区分真实内容和占位页。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
HTTP Response Handling for JavaScript-Dependent Sites
When to Use This Skill
Use this technique when you need to fetch content from websites that:
- Render content dynamically with JavaScript
- Return placeholder HTML when accessed by non-browser clients
- Deliver different content based on User-Agent headers
Core Technique
Step 1: Fetch Content with Browser-Like Headers
Use curl with a realistic User-Agent header to mimic a real browser:
curl -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" -o output.html "https://example.com"
Key flags:
-L— Follow redirects-A— Set User-Agent header to mimic a real browser-o— Save output to file for inspection
Step 2: Detect Placeholder HTML Responses
After fetching, check if you received a placeholder response instead of actual content:
# Check file size (placeholder responses are often very small)
wc -c output.html
# Check for common placeholder indicators
grep -i "javascript" output.html | head -5
grep -i "loading" output.html | head -5
grep -i "noscript" output.html | head -5
Signs of a placeholder response:
- File size is suspiciously small (<5KB for content pages)
- Contains大量 JavaScript but minimal actual content
- Has "loading", "spinner", or "noscript" tags
- Missing expected text/data from the page
Step 3: Validate File Type Before Parsing
Before attempting format-specific parsing, validate the file type:
# Check the file type
file output.html
# Check the actual content type (if you have the headers)
curl -I -A "Mozilla/5.0 ..." "https://example.com" | grep -i content-type
# Inspect first few lines
head -50 output.html
Common checks:
- HTML files: Should start with
<!DOCTYPEor<html - JSON files: Should start with
{or[ - PDF files: Should start with
%PDF - Empty/error pages: May contain error messages or generic HTML
Step 4: Handle Different Scenarios
If you got valid HTML content:
# Proceed with HTML parsing or extraction
grep -oP '(?<=<title>).*?(?=</title>)' output.html
If you got a placeholder/JS-dependent response:
- Option A: Use a headless browser (Playwright, Selenium)
- Option B: Look for an API endpoint that returns JSON directly
- Option C: Check if the site has a mobile/API version with simpler responses
If you got an unexpected file type:
# Check what was actually returned
file output.html
# Adjust your approach based on actual content
case $(file -b --mime-type output.html) in
"text/html")
# Parse as HTML
;;
"application/json")
# Parse as JSON
;;
"application/pdf")
# Handle as PDF
;;
*)
echo "Unexpected file type: $(file -b --mime-type output.html)"
;;
esac
Quick Reference Script
#!/bin/bash
# fetch-with-validation.sh
URL="$1"
OUTPUT="${2:-output.html}"
# Fetch with browser headers
curl -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" -o "$OUTPUT" "$URL"
# Get file info
SIZE=$(wc -c < "$OUTPUT")
TYPE=$(file -b --mime-type "$OUTPUT")
echo "Downloaded: $OUTPUT"
echo "Size: $SIZE bytes"
echo "Type: $TYPE"
# Warn about potential issues
if [ "$SIZE" -lt 1000 ]; then
echo "WARNING: File is very small - may be a placeholder response"
fi
if [ "$TYPE" = "text/html" ]; then
if grep -qi "javascript\|loading\|spinner" "$OUTPUT"; then
echo "WARNING: Content may be JavaScript-dependent"
fi
fi
Common Pitfalls
- Not checking file type: Assuming HTML when you got JSON or an error page
- Using default curl User-Agent: Many sites block or serve minimal content to bots
- Ignoring file size: Very small files are often error pages or placeholders
- Not following redirects: Some sites redirect based on User-Agent
常见问题
类似浏览器的请求头有什么作用?
它让请求看起来像来自普通网页浏览器,而一些网站只接受这类请求。
怎样识别占位页?
指南会检查文件是否非常小,以及是否包含加载提示或 noscript 等字样。
这个方法适用于所有网站吗?
不适用。有些页面依靠 JavaScript 渲染内容,简单下载无法运行,指南要求检查结果。
详情
作者的原始描述
Handle websites requiring JavaScript by using curl with browser headers and validating file types.
repo: HKUDS/AgentPilot
热度
- GitHub 星标
- 7.8k
- 排名
- #12892
- 许可证
- MIT
- 更新时间
- 2026/11/1
评论
- …
同一仓库的更多技能
agentpilot
7.8k帮你的智能体准备任务并运行 AgentPilot 循环,逐步改进项目:循环会提出修改、测试修改并为其打分。
openspace
7.8k帮你的智能体设置 OpenSpace,这是一个用于存储和获取智能体技能的工具,并通过 MCP 将其连接到你的 AI 应用。
rsi-arena
7.8k帮你的智能体设置并运行标准 AI 基准测试,例如 AIME 和 Terminal-Bench,用来比较不同的改进方法。
experiment-guide
7.8k帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。