SuperAPI AI 工具集

tinyfish

数据与分析

查看项目

更新于 10-16 07:12

技能介绍

用途

TinyFish(Mino)Web Agent 用于通过自然语言驱动网页抓取、数据提取和浏览器操作自动化。适合需要从网页中获取结构化数据、或对浏览器行为进行自动化控制的场景。

主要能力

  • 使用自然语言描述目标(goal)来提取或抓取网页数据。
  • 支持指定返回的 JSON 结构,便于直接获得结构化结果。
  • 支持提取单条记录,也支持提取列表数据(如商品列表)。
  • 提供 stealth 浏览器配置,用于应对有机器人防护的站点。
  • 支持代理配置,可通过 country_code 指定国家,访问有地域限制的网站。
  • 结果以 SSE 流式事件返回,在 COMPLETE 事件中读取 resultJson 字段。

使用方式

需要设置 MINO_API_KEY 环境变量。通过向 https://mino.ai/v1/automation/run-sse 发送 POST 请求调用,请求头包含 X-API-Key 与 Content-Type: application/json,请求体中提供 url 与 goal。goal 中应明确描述期望的 JSON 结构。

基础提取示例(Python):

import requests
import json
import os

response = requests.post(
    "https://mino.ai/v1/automation/run-sse",
    headers={
        "X-API-Key": os.environ["MINO_API_KEY"],
        "Content-Type": "application/json",
    },
    json={
        "url": "https://example.com",
        "goal": "Extract product info as JSON: {\"name\": str, \"price\": str, \"in_stock\": bool}",
    },
    stream=True,
)

for line in response.iter_lines():
    if line:
        line_str = line.decode("utf-8")
        if line_str.startswith("data: "):
            event = json.loads(line_str[6:])
            if event.get("type") == "COMPLETE" and event.get("status") == "COMPLETED":
                print(json.dumps(event["resultJson"], indent=2))

提取列表数据:

json={
    "url": "https://example.com/products",
    "goal": "Extract all products as JSON array: [{\"name\": str, \"price\": str, \"url\": str}]",
}

Stealth 模式(用于有机器人防护的站点):

json={
    "url": "https://protected-site.com",
    "goal": "Extract product data as JSON: {\"name\": str, \"price\": str, \"description\": str}",
    "browser_profile": "stealth",
}

代理(指定国家):

json={
    "url": "https://geo-restricted-site.com",
    "goal": "Extract pricing data as JSON: {\"item\": str, \"price\": str, \"currency\": str}",
    "browser_profile": "stealth",
    "proxy_config": {
        "enabled": True,
        "country_code": "US",
    },
}

最佳实践

  • 始终明确描述期望返回的 JSON 结构。
  • 从多个独立站点提取数据时,应分别发起并行调用,而不是合并到一个提示中。
  • 每个独立的提取任务应作为单独的 API 调用,这样更快(并行执行)也更可靠。

并行调用示例(推荐):

# Compare pizza prices - run these simultaneously
call_1 = extract("https://pizzahut.com", "Extract pizza prices as JSON: [{\"name\": str, \"price\": str}]")
call_2 = extract("https://dominos.com", "Extract pizza prices as JSON: [{\"name\": str, \"price\": str}]")

不推荐(合并为单次调用):

# Don't do this - less reliable and slower
extract("https://pizzahut.com", "Extract prices from Pizza Hut and also go to Dominos...")

适用场景

  • 从网页提取商品信息、价格、库存等结构化数据。
  • 从列表页批量提取多条记录。
  • 访问有机器人防护或地域限制的站点并提取数据。
  • 对多个独立来源进行并行数据采集与对比。

限制

  • 需要 MINO_API_KEY 环境变量,具体获取方式与收费信息暂未提供。
  • 结果需从 SSE 事件的 COMPLETE 事件中读取 resultJson 字段。
  • 其他平台支持、配额与速率限制等信息暂未提供。