跳到正文
DEV Community· Mohamed Senator·· 4 小時前AI 評分55

Webpage to JSON for AI Agents 將任意網頁轉為帶來源引文的型別化 JSON

Turn any web page into typed JSON for your AI agent (with a source quote for every value)

AI 導讀

Webpage to JSON for AI Agents 接收網址及自然語言欄位描述,輸出型別化 JSON,並為資料值附上網頁引文供核對。它支援 extractionSchema 指定結構、listMode: true 批量擷取,requireEvidence 預設開啟,缺少引文的值會列入 unverifiedFields。

正文

Mohamed Senator

LLM agents are great at reasoning and bad at reading messy HTML. The usual fix is a custom scraper per site, which breaks every time the site changes.

Webpage to JSON for AI Agents takes a URL and a plain-English description of the fields you want, and returns typed JSON. Every value comes with a quote from the page, so you can check it isn't made up.

Input:

{
  "urls": ["https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html"],
  "instruction": "Extract the book title, price as a number, currency code, and whether it is in stock."
}

Output (real run):

{
  "data": { "title": "A Light in the Attic", "price": 51.77, "currencyCode": "GBP", "inStock": true },
  "evidence": { "title": "# A Light in the Attic", "price": "£51.77" },
  "unverifiedFields": []
}

Useful options

  • JSON schema: pass extractionSchema when you need an exact shape.
  • List mode: set listMode: true to get many records from one page, such as product grids or job boards.
  • Strict evidence: requireEvidence is on by default. A value without a source quote is flagged in unverifiedFields.

Call it from code

from apify_client import ApifyClient
client = ApifyClient("<YOUR_APIFY_TOKEN>")
run = client.actor("s3nafps/webpage-to-json-for-ai-agents").call(run_input={
    "urls": ["https://example.com/pricing"],
    "instruction": "List each plan with name, monthly price and included seats."
})
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item["data"])

Use it as an MCP tool: add https://mcp.apify.com/?actors=s3nafps/webpage-to-json-for-ai-agents to Claude, Cursor or any MCP client, and your agent can call it directly.

The LLM cost is included. You pay $0.03 per page with data and nothing for pages where no data was found.

來源:DEV Community · dev.to