WebExtrator 智慧擷取 API 整合指南

POST https://api.01ai.cloud/webextrator/extract

WebExtrator 智慧擷取 API 把一個 URL 轉換成類型化的結構化結果 —— 文章、商品、 食譜、影片、討論、招聘等,同時附帶清理後的 Markdown 與純文字。當你想要「乾淨的 結構化資料」而不是原始 HTML 時,這是該用的介面。

申請流程

要使用 WebExtrator 服務頁,首先到 零壹AI 控制台 取得您的 API Token,留作備用。

如果你尚未登入或註冊,會自動跳轉到登入頁面邀請你註冊和登入,完成後會自動返回目前頁面。

通用應用程式的 API Key 可用於帳號已開放的服務;專用應用程式的 Key 按該應用程式的服務範圍使用。請檢查 Key 的權限、有效期和限額,並確認應用程式餘額足以支付本次請求。可用試用額度以帳號顯示為準,餘額不足時點擊「儲值」按鈕即可。

📘 完整文件:WebExtrator 服務頁 →

驗證

Authorization: Bearer YOUR_API_KEY
Content-Type:  application/json

請求參數

Extract 接受所有Render API 的參數 (url、user_agent、timeout、wait_until、delay、wait_for_selector、 block_resources、headers、cookies、callback_url、bypass_cache、 cache_ttl_seconds、async),外加兩個 Extract 專屬欄位:

欄位 類型 必填 預設 說明
expected_type enum ❌ 自動判斷 頁面類型提示:product / article / general。指定期望的結果類型。
enable_llm boolean ❌ false 當 schema.org 未命中時允許呼叫 LLM 擷取。在 Amazon / HN / Greenhouse 這類沒有 JSON-LD 的頁面上,需要啟用才能取得類型化結果。

同步回應

{
  "success": true,
  "task_id": "550e8400-e29b-41d4-a716-446655440000",
  "trace_id": "550e8400-e29b-41d4-a716-446655440001",
  "started_at": 1777717800.123,
  "finished_at": 1777717802.535,
  "elapsed": 2.412,
  "data": {
    "kind": "extract",
    "url": "https://en.wikipedia.org/wiki/Diffbot",
    "finalUrl": "https://en.wikipedia.org/wiki/Diffbot",
    "contentType": "article",
    "title": "Diffbot",
    "description": "American machine learning and knowledge management company",
    "byline": "Contributors to Wikimedia projects",
    "language": "en",
    "siteName": "Wikipedia",
    "publishedAt": "2007-08-08T05:47:27Z",
    "images": ["https://en.wikipedia.org/static/images/icons/enwiki-25.svg"],
    "links": ["https://en.wikipedia.org/wiki/Machine_learning"],
    "markdown": "# Diffbot\n\nDiffbot is a developer of machine learning ...",
    "text": "Diffbot is a developer of machine learning algorithms ...",
    "structured": {
      "schemaOrg": { "primary": { /* 类型化实体 */ }, "breadcrumbs": [], "all": [] },
      "openGraph": { "title": "...", "description": "...", "image": "...", "type": "..." },
      "jsonLd": [ /* 原始 JSON-LD */ ]
    },
    "rawSignals": {
      "hasJsonLd": true,
      "title": "Diffbot - Wikipedia",
      "metaDescription": null,
      "pageStatus": 200,
      "textLength": 11473
    },
    "elapsedMs": 2412
  }
}

頂層欄位

欄位 類型 說明
kind string 固定為 "extract"。
url string 你提交的 URL。
finalUrl string 重新導向後的最終 URL。
contentType enum 頁面類型:product / article / general。
title string 頁面標題。
description string? 頁面描述或摘要。
byline string? 作者、頻道或公司。
language string? <html lang>。
siteName string? og:site_name。
publishedAt string? 發布時間,使用 ISO 8601 格式。
images string[] 最多 50 個 <img src>,已解析為絕對 URL、去除重複項、捨棄 data: URI。
links string[] 最多 100 個外部連結,已篩除片段 / javascript: / mailto: / tel:。
markdown string 頁面的 Markdown 內容。
text string 頁面純文字。
structured object 完整結構化結果,見下。
rawSignals object 除錯用的診斷資訊。
cached boolean? 命中快取時為 true。
cacheStoredAt number? 快取項目首次寫入的 Unix 毫秒時間戳記。

data.structured 子欄位

子欄位 何時出現 說明
schemaOrg 一律出現 { primary, breadcrumbs, all }。primary 是最高優先級的類型化實體;找不到時為 null。
openGraph 一律出現 { title, description, image, type },源自 <meta property="og:*">。
jsonLd 一律出現 所有 <script type="application/ld+json"> 區塊的原始 JSON 陣列。
llm LLM 執行且成功時 { kind, data, model, promptCharCount },類型化結果。
llmError LLM 執行但失敗時 { kind, error, model },請求仍可返回其他已擷取欄位。
amazon URL 是 amazon.* 時 舊版 Amazon 擴充結果;新整合請使用類型化結果。

schema.org 結果類型

structured.schemaOrg.primary 支援以下結果類型:

schema.org 類型 kind 輸出欄位
Product product name, sku, gtin, model, color, brand, url, images, offer.{price,currency,availability,condition,seller}, rating.{value,count}, reviews[], properties[]
Recipe recipe name, description, image, datePublished, author, cookTime, prepTime, totalTime, recipeYield, ingredients[], instructions[], nutrition, rating, keywords, recipeCategory, recipeCuisine
VideoObject video name, description, thumbnailUrl, uploadDate, duration, embedUrl, contentUrl, channel, interactionCount
JobPosting job title, description, datePosted, validThrough, hiringOrganization, jobLocation, baseSalary, employmentType
Event(含 *Event) event name, description, startDate, endDate, location.{name,address}, organizer, offer.{url,price,currency}
Article / NewsArticle / BlogPosting / ScholarlyArticle / TechArticle / Report / *NewsArticle article subtype, headline, description, datePublished, dateModified, author, publisher, image[], url, sameAs[]
FAQPage faq questions[{question, answer}]
BreadcrumbList (掛在 sibling) 始終輸出至 structured.schemaOrg.breadcrumbs[],不會作為 primary。

LLM 結果類型

當 enable_llm: true 且頁面沒有可用的 schema.org 結構化資料時,可回傳以下類型的擷取結果:

Kind 必填欄位 選填欄位
article headline description, byline, publishedAt, language, topics[], sections[{heading,summary}]
product name description, brand, sku, price, currency, availability, rating.{value,count}, bullets[], specifications[{name,value}]
discussion title author, postedAt, points, commentCount, body, url
recipe name description, author, cookTime, prepTime, totalTime, recipeYield, ingredients[], instructions[], nutrition, rating, keywords[]
video name description, channel, uploadDate, duration, viewCount, likeCount, thumbnailUrl, transcript
job title description, company, location, remote, employmentType, datePosted, validThrough, salaryMin, salaryMax, salaryCurrency, salaryPeriod, responsibilities[], qualifications[]

快取

相同 URL、請求參數、cookies 和 headers 可以重複使用快取結果;async、bypass_cache、cache_ttl_seconds 用於控制執行方式和快取行為。

欄位 效果
bypass_cache: true 跳過讀取;本次結果仍會寫回快取,下次相同請求能命中。
cache_ttl_seconds: 0 本次回應不快取。
cache_ttl_seconds: N 自訂此項目的 TTL(預設 3600 秒)。

命中快取的回應會附帶 data.cached: true 與 data.cacheStoredAt: <unix-ms>。

非同步模式與回呼

設定 async: true 進入非同步模式(提供 callback_url 也會自動進入)。平台立即回傳(HTTP 200):

{
  "success": true,
  "task_id": "550e8400-...",
  "trace_id": "6ba7b810-...",
  "started_at": 1777717800.123
}

任務完成時將完整 envelope 以 POST 傳送至你的 callback_url(如果已設定)。也可以事 後透過 /webextrator/tasks 主動查詢。

範例

1. Wikipedia 文章(schema.org 命中,不需要 LLM)

curl -X POST https://api.01ai.cloud/webextrator/extract \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://en.wikipedia.org/wiki/Diffbot",
    "expected_type": "article"
  }'

data.structured.schemaOrg.primary 關鍵欄位:

{
  "kind": "article",
  "subtype": "Article",
  "headline": "American machine learning and knowledge management company",
  "datePublished": "2007-08-08T05:47:27Z",
  "dateModified": "2025-07-10T20:42:45Z",
  "author": { "name": "Contributors to Wikimedia projects", "type": "Organization" },
  "publisher": { "name": "Wikimedia Foundation, Inc." }
}

2. BestBuy 商品頁(schema.org 命中)

curl -X POST https://api.01ai.cloud/webextrator/extract \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://www.bestbuy.com/product/apple-airpods-pro-2nd-generation-white/JJ8ZH6TPSW",
    "expected_type": "product"
  }'

schema.org 擷取結果:

{
  "kind": "product",
  "name": "Apple - Refurbished Excellent - AirPods Pro (2nd generation) - White",
  "sku": "10845412",
  "model": "MQD83AM/A",
  "color": "White",
  "brand": "Apple",
  "offer": { "price": 159.99, "currency": "USD", "availability": "https://schema.org/InStock", "seller": "Best Buy" },
  "rating": { "value": 4.4, "count": 8 }
}

3. AllRecipes 食譜頁(含營養與步驟)

curl -X POST https://api.01ai.cloud/webextrator/extract \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://www.allrecipes.com/recipe/16354/easy-meatloaf/"
  }'

schema.org 擷取結果:

{
  "kind": "recipe",
  "name": "Easy Meatloaf",
  "cookTime": "PT60M",
  "totalTime": "PT75M",
  "recipeYield": "8 / 1 (9x5-inch) meatloaf",
  "ingredients": ["1 1/2 pounds ground beef", "..."],
  "instructions": [{ "text": "Preheat oven to 350°F ..." }, "..."],
  "rating": { "value": 4.7, "count": 9348 }
}

4. HN 討論頁(無 JSON-LD —— 需要啟用 LLM)

curl -X POST https://api.01ai.cloud/webextrator/extract \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://news.ycombinator.com/item?id=37000000",
    "enable_llm": true
  }'

data.structured.llm.data:

{
  "kind": "discussion",
  "title": "Show HN: A new way to extract web pages",
  "author": "alice",
  "points": 173,
  "commentCount": 42,
  "body": "Hi HN, we built a self-hosted alternative to Diffbot's Analyze API ..."
}

頂層欄位也被回填:byline = "alice"、publishedAt = "..."。

5. Amazon 商品頁(Amazon 無 JSON-LD —— 需要啟用 LLM)

curl -X POST https://api.01ai.cloud/webextrator/extract \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://www.amazon.com/dp/B0BSHF7WHW",
    "expected_type": "product",
    "enable_llm": true
  }'

data.structured.llm.data(型別化的 product):

{
  "kind": "product",
  "name": "Apple 2023 MacBook Pro M2 Pro 14-inch",
  "brand": "Apple",
  "price": 1799,
  "currency": "USD",
  "bullets": ["Apple M2 Pro chip with 10-core CPU", "..."],
  "specifications": [{ "name": "Display size", "value": "14.2 inches" }, "..."]
}

Python (requests)

import os, requests

API_KEY = os.environ["ACEDATA_API_KEY"]

resp = requests.post(
    "https://api.01ai.cloud/webextrator/extract",
    headers={
        "Authorization": f"Bearer {API_KEY}",
        "Content-Type": "application/json",
    },
    json={
        "url": "https://en.wikipedia.org/wiki/Diffbot",
        "expected_type": "article",
    },
    timeout=120,
)
resp.raise_for_status()
data = resp.json()["data"]

primary = (data.get("structured") or {}).get("schemaOrg", {}).get("primary")
print("contentType:", data["contentType"])
print("title:      ", data["title"])
print("byline:     ", data.get("byline"))
print("publishedAt:", data.get("publishedAt"))
if primary and primary["kind"] == "article":
    print("headline:    ", primary["headline"])
    print("dateModified:", primary.get("dateModified"))

Node.js (fetch)

const apiKey = process.env.ACEDATA_API_KEY;

const res = await fetch('https://api.01ai.cloud/webextrator/extract', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${apiKey}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    url: 'https://www.allrecipes.com/recipe/16354/easy-meatloaf/',
  }),
});
const { data } = await res.json();
const recipe = data?.structured?.schemaOrg?.primary;
console.log(recipe.name, recipe.cookTime, recipe.ingredients.length, '种配料');

提示與注意事項

  • 需要指定頁面類型時傳入 expected_type。 例如文章頁使用 article,商品頁使用 product。
  • enable_llm: true 在符合 schema.org 的頁面上是免費的。 LLM 只在 schema.org 沒有 primary 時才會被呼叫,所以預設開啟也很安全。
  • 偵錯時先看 rawSignals.hasJsonLd。 如果是 true 但 structured.schemaOrg.primary 為 null,表示頁面的 @type 暫不受支援,可向我們回報。
  • structured.llmError 僅供參考。 請求仍可成功回傳其他已擷取欄位。查看 llmError.error 來找出原因(逾時、JSON 解析失敗、結構驗證失敗)。
  • 非文章頁的 links[] 不會進行相關性排序。 僅按「上限 100 筆 + 過濾無效協定」 盡力清理。
  • 快取命中也會計費。