用于购买决策、目录丰富或竞争分析的产品研究需要从多个来源收集数据。产品研究代理通过向 Google 查询评论和专家意见、向 Amazon 查询定价和客户反馈、向 Walmart 查询替代定价,然后将所有内容综合到结构化报告中来自动化此操作。本教程使用 Scavio API 的统一端点构建这样的代理,无需管理多个 API 密钥或速率限制。
前置条件
- Python 3.10 或更高版本
- 可用的请求和并发期货
- Scavio API 密钥
- 对数据合并和格式化的基本了解
操作指南
步骤 1: 同时查询三个平台
使用 ThreadPoolExecutor 同时查询 Google、Amazon 和 Walmart 的产品名称。
from concurrent.futures import ThreadPoolExecutor
def fetch_all(product: str) -> dict:
queries = {
"google": lambda: search_google(product + " review"),
"amazon": lambda: search_amazon(product),
"walmart": lambda: search_walmart(product),
}
with ThreadPoolExecutor(max_workers=3) as ex:
futures = {name: ex.submit(fn) for name, fn in queries.items()}
return {name: fut.result() for name, fut in futures.items()}步骤 2: 从亚马逊和沃尔玛提取价格范围
从两个电子商务平台收集价格并计算最小值和最大值。
def price_range(data: dict) -> dict:
prices = []
for platform in ["amazon", "walmart"]:
for p in data[platform].get("products", [])[:5]:
ps = p.get("price", "")
if ps:
prices.append(float(ps.replace("$", "").replace(",", "")))
return {"min": min(prices) if prices else None, "max": max(prices) if prices else None}步骤 3: 提取Google评论情绪
从 Google 收集有机结果片段,其中包含评级或推荐等评论信号。
def extract_review_signals(google_data: dict) -> list[str]:
signals = []
for r in google_data.get("organic_results", [])[:5]:
snippet = r.get("snippet", "")
if any(word in snippet.lower() for word in ["recommend", "rating", "review", "best", "worth"]):
signals.append(snippet)
return signals步骤 4: 组装并打印研究报告
将价格范围、评论信号和产品数量合并到格式化的研究报告中。
def research_product(product: str) -> str:
data = fetch_all(product)
pr = price_range(data)
signals = extract_review_signals(data["google"])
lines = [f"Product Research: {product}"]
lines.append(f"Price range: ${pr['min']} — ${pr['max']}")
lines.append("Review signals:")
for s in signals[:3]:
lines.append(f" - {s[:100]}")
return "\n".join(lines)Python 示例
import os
import requests
from concurrent.futures import ThreadPoolExecutor
API_KEY = os.environ.get("SCAVIO_API_KEY", "your_scavio_api_key")
ENDPOINT = "https://api.scavio.dev/api/v1/search"
def call(body: dict) -> dict:
r = requests.post(ENDPOINT, headers={"x-api-key": API_KEY}, json=body)
r.raise_for_status()
return r.json()
def research(product: str) -> dict:
with ThreadPoolExecutor(max_workers=3) as ex:
g = ex.submit(call, {"query": f"{product} review", "country_code": "us"})
a = ex.submit(call, {"platform": "amazon", "query": product, "marketplace": "US"})
w = ex.submit(call, {"platform": "walmart", "query": product})
return {"google": g.result(), "amazon": a.result(), "walmart": w.result()}
if __name__ == "__main__":
data = research("Sony WH-1000XM5")
amazon_products = data["amazon"].get("products", [])
print(f"Amazon listings: {len(amazon_products)}")
if amazon_products:
print(f"Top Amazon price: {amazon_products[0].get('price')}")
google_count = len(data["google"].get("organic_results", []))
print(f"Google results: {google_count}")JavaScript 示例
const API_KEY = process.env.SCAVIO_API_KEY || "your_scavio_api_key";
const ENDPOINT = "https://api.scavio.dev/api/v1/search";
async function call(body) {
const res = await fetch(ENDPOINT, {
method: "POST",
headers: { "x-api-key": API_KEY, "Content-Type": "application/json" },
body: JSON.stringify(body)
});
return res.json();
}
async function research(product) {
const [google, amazon, walmart] = await Promise.all([
call({ query: `${product} review`, country_code: "us" }),
call({ platform: "amazon", query: product, marketplace: "US" }),
call({ platform: "walmart", query: product })
]);
return { google, amazon, walmart };
}
async function main() {
const data = await research("Sony WH-1000XM5");
console.log(`Amazon listings: ${data.amazon.products?.length || 0}`);
console.log(`Google results: ${data.google.organic_results?.length || 0}`);
}
main().catch(console.error);预期输出
Product Research: Sony WH-1000XM5
Price range: $249.99 — $349.00
Review signals:
- The WH-1000XM5 remains our top recommendation for noise-canceling headphones...
- Rated 4.8/5 stars across 50,000+ verified reviews on Amazon...
- Best premium wireless headphones in 2026 according to our testing...