Chuyển đến nội dung
Skillpedia
Thu thập dữ liệu web7.8k · #12892

http-response-handling

Skill này làm gì

Skill này chỉ cách tải trang web bằng yêu cầu kiểu trình duyệt và nhận ra khi trang trả về một khung trống. Dành cho người thu thập thông tin từ các trang web tải nội dung bằng JavaScript.

Khi nào nên dùng

  • ✓Khi một trang web chỉ trả về rất ít văn bản vì nội dung tải bằng JavaScript.
  • ✓Khi một trang trả về nội dung khác cho các yêu cầu tự động đơn giản.
  • ✓Khi tôi cần kiểm tra xem trang đã tải có thật sự chứa thông tin tôi cần không.

Liên kết skill

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/http-response-handling/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/http-response-handling/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Trang web tôi muốn đọc hiện ra một trang trống với AI. Hãy tải nó theo kiểu giống trình duyệt và cho tôi biết nội dung có thật sự ở đó không.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

AI tải trang bằng curl với header kiểu trình duyệt, rồi kiểm tra kích thước tệp và tìm các dấu hiệu như chữ đang tải hoặc thẻ noscript để phân biệt nội dung thật với khung giữ chỗ.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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 <!DOCTYPE or <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

  1. Not checking file type: Assuming HTML when you got JSON or an error page
  2. Using default curl User-Agent: Many sites block or serve minimal content to bots
  3. Ignoring file size: Very small files are often error pages or placeholders
  4. Not following redirects: Some sites redirect based on User-Agent
Câu hỏi thường gặp

Header kiểu trình duyệt làm gì?

Nó làm yêu cầu giống yêu cầu từ một trình duyệt web thông thường, điều mà một số trang yêu cầu.

Làm sao nhận ra trang giữ chỗ?

Hướng dẫn kiểm tra kích thước tệp rất nhỏ và các từ như loading, spinner hoặc noscript.

Cách này có hoạt động trên mọi trang không?

Không. Một số trang hiển thị nội dung bằng JavaScript mà tải đơn giản không chạy được, và hướng dẫn yêu cầu kiểm tra kết quả.

Chi tiết

Mô tả gốc của tác giả

Handle websites requiring JavaScript by using curl with browser headers and validating file types.

repo: HKUDS/AgentPilot

Độ phổ biến

Sao GitHub
7.8k
Vị trí xếp hạng
#12892
Giấy phép
MIT
Cập nhật
1/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự