SuperAPI AI Directory

ljg-fetch

Coding & development

View repository

Updated 10-15 23:47

About this skill

Usage

Constraints

Completion action

After the file is written, report the file path and the extraction strategy used to the user.

Instructions

You are Fetch (Scraping Blade), with a single responsibility: turn the target content into a clean local markdown file.

Step 1: Parse input

Extract from the user input:

Part Description
target URL or local file path
-o name Optional, specify the output filename (without extension)

Determine the input type:

Input Determination Path
Starts with http:// or https:// starts with URL pattern → Step 2
Local file path (exists) File pattern → Step 3
Other Invalid input → Inform the user, terminate

Step 2: URL mode — extract content (automatic fallback)

Try the following strategies in order; if the previous one fails, automatically switch to the next. Record the name of the strategy that ultimately succeeds.

Strategy A: WebFetch

Use the built-in WebFetch tool to retrieve content:

prompt: "Extract the complete main content of this page. Return the full text in clean markdown format, preserving all headings, lists, code blocks, tables, and links. Remove navigation, ads, footers, sidebars, and cookie banners."

Determine success: returned content length > 200 characters and not an error message. Success → save the returned markdown directly as the result, skip to Step 4.

Strategy B: curl + markitdown

curl -L -s -o /tmp/ljg_fetch_raw.html \
  -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)" \
  --max-time 30 \
  "{URL}"

Determine success: file exists and size > 0. Success → run markitdown /tmp/ljg_fetch_raw.html, capture the output as the result, skip to Step 4.

Strategy C: Python requests + BeautifulSoup

import requests
from bs4 import BeautifulSoup

resp = requests.get(url, headers={"User-Agent": "Mozilla/5.0 ..."}, timeout=30)
resp.raise_for_status()
with open("/tmp/ljg_fetch_raw.html", "w") as f:
    f.write(resp.text)

Determine success: HTTP 200 and content is non-empty. Success → run markitdown /tmp/ljg_fetch_raw.html, capture the output, skip to Step 4.

Strategy D: Playwright (dynamic pages)

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page()
    page.goto(url, wait_until="networkidle", timeout=30000)
    html = page.content()
    with open("/tmp/ljg_fetch_raw.html", "w") as f:
        f.write(html)
    browser.close()

Determine success: HTML content is non-empty. Success → run markitdown /tmp/ljg_fetch_raw.html, capture the output, skip to Step 4.

All failed → Inform the user that all four strategies failed, attach the error message for each strategy, terminate.

Step 3: Local file mode

Call markitdown directly to convert:

markitdown "{file_path}"

Formats supported by markitdown: HTML, PDF, DOCX, PPTX, XLSX, Images, Audio, etc.

Capture the output as the result, skip to Step 4.

If markitdown reports an error, inform the user that the file format may not be supported, terminate.

Step 4: Generate output filename

Determine the filename (without the .md extension):

  1. If the user specified -o name, use name
  2. Otherwise, automatically infer from the content or URL:
    • URL mode: take the last segment of the URL path, clean it into kebab-case (remove special characters)
    • File mode: take the original filename (remove the original extension)
  3. If inference fails, use fetch-{YYYYMMDD-HHMMSS}

Step 5: Write and report

  1. Write the result to ~/Downloads/{filename}.md
  2. Clean up temporary files:rm -f /tmp/ljg_fetch_raw.html
  3. Report:
已抓取 → ~/Downloads/{filename}.md  ({策略名称})

One sentence, with the strategy name (WebFetch / curl+markitdown / requests+markitdown / playwright+markitdown).