本文在原“SP广告采集技术深度解析”的基础上,针对 优快云 读者增加更多工程细节、代码片段与图示,帮助在真实项目中落地高覆盖、低误判、分钟级时效的赞助广告采集与解析流程。以下代码均是基于Pangolin Scrape API,token 需要自行注册获取。

1. 背景与难点概览
- 高动态:关键词、时间窗、地域、用户画像、设备/视口多维变化导致展示结果差异极大。
- 异步渲染:广告模块在主内容之后异步注入,加载时机抖动带来漏数或超时。
- 跨语言与跨站:.com/.co.uk/.de 等模板差异,赞助标识文案与ARIA属性不同。
- 风控与对抗:IP信誉、指纹识别、Bot 检测、CAPTCHA、异常行为拦截等。
2. 赞助位识别:多特征融合(示例选择器)
// JS DOM 识别示例(需结合站点模板实际调整)
const nodes = [
...document.querySelectorAll('[data-component-type="sp-sponsored-result"]'),
...document.querySelectorAll('.s-sponsored-label-text'),
...document.querySelectorAll('[aria-label*="Sponsored" i]'),
...document.querySelectorAll('[aria-label*="赞助" i]'), // CN 站点
];
// 结合上下文容器进行鲁棒判断
function isSponsored(node) {
const labelText = (node.textContent || '').toLowerCase();
const aria = (node.getAttribute('aria-label') || '').toLowerCase();
const inSponsoredContainer = !!node.closest('[data-component-type="sp-sponsored-result"]');
return (
inSponsoredContainer ||
labelText.includes('sponsored') ||
labelText.includes('赞助') ||
aria.includes('sponsored') ||
aria.includes('赞助')
);
}
3. 结构化抽取:字段统一
// TypeScript 类型约定(示例)
type SponsoredItem = {
asin: string;
title: string;
price?: number;
rating?: number;
reviews?: number;
seller?: string;
slot_index?: number; // 广告位序号
exposure_region?: string; // 顶部/中部/底部等
sponsored_label: boolean;
};
4. 采集闭环:采样与质量监控
flowchart LR
A[采样参数设定\n(时间窗, 地域, 视口, 画像)] --> B[请求调度\n代理编排 / 速率控制]
B --> C[页面加载与事件监听\n就绪信号判定]
C --> D[赞助位检测\n多特征融合]
D --> E[结构化抽取\nASIN/价格/评分等]
E --> F[去重与版本化\n批次管理]
F --> G[自动化回归校验\n覆盖率/误判率]
G --> H[结果入库\n分钟级落地]
注:如平台不支持 Mermaid,可替换为 ASCII 图或导入图片形式。
5. Scrape API 调用示例(以官方文档为准)
curl --request POST \
--url https://scrapeapi.pangolinfo.com/api/v1/amazon/sponsored-ads/search \
--header 'Authorization: Bearer <YOUR_TOKEN>' \
--header 'Content-Type: application/json' \
--data '{
"keyword": "wireless earbuds",
"marketplace": "US",
"formats": ["json"],
"bizContext": { "zipcode": "10041" },
"options": { "includeOrganic": false, "viewport": "desktop" }
}'
{
"sponsored": [
{
"asin": "B0XXXXXXX",
"title": "Wireless Earbuds with Noise Cancellation",
"price": 49.99,
"rating": 4.5,
"reviews": 10234,
"seller": "BrandA",
"slot_index": 1,
"sponsored_label": true
},
{ "asin": "B0YYYYYYY", "slot_index": 2, "sponsored_label": true }
],
"meta": { "keyword": "wireless earbuds", "marketplace": "US", "geo": "10041" }
}
6. 效果验证与指标
- 覆盖率:≈98%(多站点/多语言综合采样)
- 误判率:≤2%(多特征融合 + 抽样人工校验)
- 时效:分钟级落地
7. 工程实践建议
- 参数化与可复现:明确时间窗、地域、视口、画像,保障对比的可复现性。
- ROI 优先:在电商垂直场景,优先复用专业API(如 Pangolin Scrape API)。
- 合规与治理:速率/频次控制、日志与版本化管理,确保长期稳定交付。
838

被折叠的 条评论
为什么被折叠?



