SuperAPI AI 工具集

crawlberg-scraping-html-to-markdown

数据与分析

查看项目

更新于 10-16 07:18

技能介绍

用途:当用户只想处理单个页面,并希望得到干净的 Markdown 加结构化元数据时,使用 crawlberg scrape <url>。它会返回 Markdown 和完整结构化载荷(元数据、链接、图片、JSON-LD、HTTP 响应信息)。

主要能力:支持 --format 选择 json(默认)或 markdown;可设置 --timeout(默认 30000 毫秒)、--proxy(HTTP/HTTPS/SOCKS5)、--user-agent、--respect-robots-txt(默认关闭)、--browser-mode(auto/always/never)与 --browser-endpoint(外部 CDP ws:// URL),并可用 --config 传入内联 JSON 或 @file.json 指定完整 CrawlConfig。

输出:markdown 模式只打印渲染后的 Markdown,适合写入文件或作为 LLM 上下文。JSON 模式返回 ScrapeResult,含 final_url、status_code、content_type、body_size、detected_charset;markdown 对象含 content、fit_content(裁剪后的 LLM 优化版)、tables、warnings;metadata 含 Open Graph、Twitter Card、Dublin Core、文章标签、H1–H6 标题、favicon、hreflang;links 为扁平数组,含 link_type(internal/external/anchor/document);另有 images、feeds、json_ld 与 response_meta。脚本中读取 result.markdown.content 获取 Markdown 字符串。

常见问题:若静态抓取只得到 JS 外壳,表现为 markdown.content 过短、仅含导航页脚、warnings 提示需要 JS 渲染或 headings 为空,可改用 --browser-mode always。auto 模式会自动识别 8 种 WAF 并通过 headless Chrome 重试;若强制 never 则 WAF 响应会直接返回,可通过 403/406/503 与 WAF 响应头判断。启用 --respect-robots-txt 且路径被禁止时会返回错误而非部分内容,只应在自有或获授权的站点关闭该限制。页面错误声明字符集可能导致乱码,crawlberg 不提供编码覆盖选项,需重新获取原始字节并在下游转码。

示例:crawlberg scrape https://blog.example.com/post-123 --format markdown > /tmp/article.md;crawlberg scrape https://example.com --proxy http://proxy.internal:3128 --user-agent "crawlberg (research@example.com)" --format json;crawlberg scrape https://example.com --format json | jq '.metadata | {title: .og_title, description: .og_description, image: .og_image}'。

适用与替代:需要整站抓取用 crawlberg-crawling-a-site;需要点击、输入或滚动后再提取用 crawlberg interact;只想获取 URL 列表用 crawlberg map。