跨境电商选品工具链 · Cross-border e-commerce product-research toolkit
中文 · English
从 Shopee 搜索页采集真实竞品数据 → 清洗打分 → 利润测算 → 导出/看板。全链路在本机运行,不依赖任何第三方数据服务。
仓库内有两条产品线,能力互补,不是新旧版本关系:
| A. Shopee Scout | B. SELEKT | |
|---|---|---|
| 位置 | 仓库根目录 + extension/ |
selekt/ |
| 形态 | 采集扩展 + 单文件 Python 分析引擎 | 采集扩展 + 双 FastAPI 后端 + Web 看板 |
| 数据提取 | 三层:API 拦截 → SSR 注入 → DOM 兜底 | DOM 单层 |
| 站点覆盖 | 8 个(含 *.xiapibuy.com) |
8 个 Shopee 官方域名 |
| 数据落点 | CSV / Excel 文件 | SQLite + Web 看板 + 定时任务 |
| 评分 | 毛利率 + 销量 + 风险分级 | 采集端 90 分制 + 分析端加权分制 |
| 适合 | 轻量、一次性选品调研 | 持续监控、多关键词日常运营 |
想要最强的数据抓取能力 → 用 A 的
extension/。 想要看板、定时采集、历史沉淀 → 用 B 的selekt/。
pip install openpyxl requests beautifulsoup4
python main.py # 跑示例数据
python main.py data/你的商品.csv # 跑自己的数据Chrome 扩展:chrome://extensions → 开启开发者模式 → 加载已解压的扩展 → 选 extension/
cd selekt
bash install.sh # 一键装依赖 + 建虚拟环境 + 初始化授权
bash start.sh # 同时启动两个后端Chrome 扩展:加载 selekt/shopee-collector/
⚠️ install.sh/start.sh/stop.sh是 macOS / Linux 专用(依赖nohup、/tmp、pkill、.venv/bin/activate)。Windows 请按selekt/shopee-backend/README.md的手动步骤用.venv\Scripts\activate启动。
搜索页加载
│
├─ 层1 API 拦截(优先)
│ 劫持 window.fetch / XMLHttpRequest,捕获 Shopee 内部
│ search_items 响应 → 完整结构化数据(价格/销量/评分/库存/店铺)
│ 注意:价格在接口里以 ×100000 存储,需还原
│
├─ 层2 SSR 嵌入式数据(备选)
│ window.__INITIAL_STATE__ / __NEXT_DATA__ / application/json
│
└─ 层3 DOM 提取(兜底)
多选择器兼容 data-sqe → class → aria-label
跨域文本扫描:RM/₱/$ 价格格式 + sold/已售/terjual 销量格式
xiapibuy.com 是服务端渲染,content_scripts 注入不到 —— 用 chrome.scripting.executeScript 配合 run_at: document_start 在渲染前挂上钩子。
| 方案 | 风险 | 维护成本 | 数据质量 |
|---|---|---|---|
| Selenium / Playwright 模拟浏览器 | 易被检测封 IP | 高 | 中 |
| requests 直接请求 | 403 拦截 | 高 | 低 |
| 第三方代理池 | 贵且不稳定 | 高 | 中 |
| Chrome 扩展 + 用户自身会话 | 不触发 403 | 低 | 最高 |
扩展复用用户浏览器的 cookies 和会话,且只做监听不改 DOM、不额外发请求。Shopee 看到的请求与用户正常搜索无异。selekt/shopee-backend/ 里的 Playwright 方案是另一条独立路径,指纹风险高于扩展。
- 采集端 · 规则加分制(
shopee-backend/scraper.py、shopee-collector/content.js) 8 项加分,实际满分 90(不是 100),输出score+ 四档 verdict:强烈推荐 ≥80 / 可以测款 ≥70 / 谨慎考虑 ≥60 / 直接放弃。 - 分析端 · 加权分制(
selekt-frontend/main.py)需求 40% + 竞争 30% + 物流 30%,权重可运行时调整(和必须 = 1),输出 S/A/B/C 分级 + 利润率。
跨库导入时,采集端的 score 只用于 min_score 过滤,verdict 映射成 track/watch/pass;分析端会重新算一套自己的分。两者口径不同,不要直接比对。
支持 8 个市场的币种、价格分段、物流费、佣金率与汇率:
净利 = 售价 − (采购价 × 汇率 + 物流基础费 + 重量 × 每kg费 + 售价 × 佣金率)
并给出 20% / 30% / 40% 目标利润率对应的建议定价
shopee-analyzer/
├── extension/ A · 采集扩展(MV3,三层提取)
│ ├── manifest.json
│ ├── content/
│ │ ├── content.js fetch/XHR API 拦截 + DOM 提取
│ │ └── extract.js SSR → API → DOM 三层提取注入脚本
│ └── popup/
│ ├── popup.html
│ ├── popup.js 交互 + CSV 导出
│ └── popup.css
│
├── main.py A · 选品分析引擎
├── crawler.py A · Playwright 备用爬虫
├── exporter.py A · Excel / CSV 导出
├── product.py A · 数据模型
├── config.py A · 全局配置
├── data/template.csv A · 数据模板
│
├── selekt/ B · 全链路版
│ ├── install.sh 一键部署(Unix)
│ ├── start.sh / stop.sh / restart.sh
│ ├── license.py 授权模块(环境变量启用,未设置则停用)
│ ├── selekt-frontend/ 分析后端 :8002 + Web 看板(7 页 SPA)
│ │ ├── main.py 30 个 API 端点
│ │ ├── index.html 单文件 SPA(内联 CSS+JS + Chart.js)
│ │ ├── markets.py 8 市场配置中心
│ │ └── requirements.txt
│ ├── shopee-backend/ 采集后端 :8000
│ │ ├── main.py 19 个 API 端点
│ │ ├── scraper.py Playwright + XHR 拦截 + 打分
│ │ ├── database.py aiosqlite 异步数据层
│ │ ├── markets.py 与 selekt-frontend 同源
│ │ ├── templates/dashboard.html
│ │ └── requirements.txt
│ └── shopee-collector/ 采集扩展(MV3)
│ ├── manifest.json
│ ├── background.js Service Worker:轮询 → 认领 → 开 Tab
│ ├── content.js DOM 采集 + 打分 + 回传
│ ├── relay.js 端口保活,防止 SW 休眠
│ └── popup/
│
├── .github/workflows/ Pylint
└── README.md
| 层 | 技术 | 用途 |
|---|---|---|
| 数据采集 | Chrome Extension MV3 | 浏览器端数据捕获(两条产品线共用思路) |
| 脚本注入 | chrome.scripting API |
SSR 页面动态注入 |
| 底层爬虫 | Playwright (Python) | 无头浏览器备用方案 |
| 分析后端 | FastAPI + SQLite | 选品评分、利润测算、看板 API |
| 采集后端 | FastAPI + aiosqlite + APScheduler | 采集调度、定时任务、SSE 进度推流 |
| 前端看板 | 原生 HTML/CSS/JS + Chart.js | 7 页单文件 SPA |
| 数据格式 | CSV / XLSX / SQLite | 兼容 Excel / WPS |
| 授权 | HMAC-SHA256 密钥 | 3 天试用 + 正式密钥 |
selekt/license.py 不含任何硬编码密钥。从环境变量读取:
export SELEKT_LICENSE_SECRET="<你的密钥>"
# 生成密钥
python -c "import secrets;print(secrets.token_urlsafe(32))"
# 查看状态 / 生成授权密钥
python license.py
python license.py key <install_id> [有效天数]- 未设置该变量 → 授权模块自动停用,所有 API 放行,可零配置运行。
- 已设置 → 启用 3 天试用;试用到期或密钥过期后,除授权相关端点外的所有 API 返回
402。
授权数据存于 ~/.selekt/。
诚实列出,避免误用:
- 自动化采集目前只能跑台湾站。 采集端
pending-tasks已返回任务的market,但派发端(background.js)尚未把 market 写进 URL,因此自动采集一律走shopee.tw。手动采集的弹窗也只放行shopee.tw。 - 扩展端的价格解析对部分市场失效。
selekt/shopee-collector/content.js的价格正则匹配美元符号,印尼(Rp)、泰国(฿)、越南(₫)取不到价格;且它的价格分段写死为台湾区间,与后端markets.price_score()不一致。多市场采集请优先用extension/(Shopee Scout)。 - 分析端的部分数据是演示值。
dashboard/ai_insight、dashboard/ticker、competitors/summary、competitors/price_distribution、trend/*、radar/*均为硬编码 mock,尚未接入真实数据源。采集端shopee-backend的数据是真实的。 - 两个 SQLite 库不随仓库分发(已在
selekt/.gitignore中忽略),首次启动自动建表。 - 部署脚本是 Unix-only,Windows 需按子目录 README 手动启动。
price_twd字段名在多市场下有歧义 —— 它实际存的是"当地币种售价",非台湾站商品也会写进这一列,跨市场聚合统计时需注意。
MIT — 欢迎 Fork、Star、提 Issue。
如需洽谈,请通过 GitHub Issues。
Scrape real competitor data from Shopee search pages → clean & score → profit modelling → export / dashboard. Everything runs locally, no third-party data service required.
This repo contains two product lines. They complement each other — they are not old and new versions of the same thing.
| A. Shopee Scout | B. SELEKT | |
|---|---|---|
| Location | repo root + extension/ |
selekt/ |
| Shape | capture extension + single-file Python analysis engine | capture extension + two FastAPI backends + web dashboard |
| Extraction | three layers: API intercept → SSR injection → DOM fallback | DOM only |
| Sites | 8 domains incl. *.xiapibuy.com |
8 official Shopee domains |
| Output | CSV / Excel files | SQLite + web dashboard + scheduled jobs |
| Scoring | margin + sales + risk tier | 90-point rule score + weighted score |
| Best for | lightweight, one-off research | continuous monitoring, day-to-day ops |
Want the strongest capture capability → use A's
extension/. Want a dashboard, scheduled collection and history → use B'sselekt/.
pip install openpyxl requests beautifulsoup4
python main.py # sample data
python main.py data/your_products.csv # your own dataExtension: chrome://extensions → enable Developer mode → Load unpacked → pick extension/
cd selekt
bash install.sh # deps + venv + licence init
bash start.sh # start both backendsOpen http://localhost:8002/ui, then load selekt/shopee-collector/ as an unpacked extension.
⚠️ install.sh/start.sh/stop.share macOS / Linux only (they rely onnohup,/tmp,pkilland.venv/bin/activate). On Windows, follow the manual steps inselekt/shopee-backend/README.mdusing.venv\Scripts\activate.
Search page loads
│
├─ Layer 1 API intercept (preferred)
│ Hook window.fetch / XMLHttpRequest, capture Shopee's internal
│ search_items response → full structured data
│ Note: prices are stored ×100000 in the API and must be scaled down
│
├─ Layer 2 Embedded SSR data (fallback)
│ window.__INITIAL_STATE__ / __NEXT_DATA__ / application/json
│
└─ Layer 3 DOM extraction (last resort)
Multi-selector: data-sqe → class → aria-label
Cross-locale text scan: RM/₱/$ price formats, sold/已售/terjual
xiapibuy.com is server-rendered, so content_scripts cannot attach — we inject via chrome.scripting.executeScript with run_at: document_start, hooking before render.
| Approach | Risk | Maintenance | Data quality |
|---|---|---|---|
| Selenium / Playwright | detectable, IP bans | high | medium |
Raw requests |
403 blocked | high | low |
| Proxy pools | costly, unstable | high | medium |
| Chrome extension + user session | no 403 | low | highest |
The extension reuses the browser's own cookies and session, and only listens — it never mutates the DOM and sends no extra requests. Shopee sees exactly the traffic a normal search produces. The Playwright path inside selekt/shopee-backend/ is a separate route with a higher fingerprinting risk.
- Capture side · additive rule score (
shopee-backend/scraper.py,shopee-collector/content.js) 8 weighted items, 90 points actually achievable (not 100). Emitsscoreplus one of four verdicts: strongly recommend ≥80 / worth testing ≥70 / consider carefully ≥60 / skip. - Analysis side · weighted score (
selekt-frontend/main.py)demand 40% + competition 30% + logistics 30%, weights adjustable at runtime (must sum to 1). Emits an S/A/B/C grade plus margin.
On cross-database import, the capture-side score is only used as a min_score filter and verdict is mapped to track/watch/pass; the analysis side then computes its own score from scratch. The two are not directly comparable.
Currency, price tiers, shipping cost, commission and FX rate for 8 markets:
net = price − (source_price × fx + base_shipping + weight × per_kg + price × commission)
Also returns the price needed to hit 20% / 30% / 40% target margins.
shopee-analyzer/
├── extension/ A · capture extension (MV3, three-layer)
├── main.py A · product-research engine
├── crawler.py A · Playwright fallback crawler
├── exporter.py A · Excel / CSV export
├── product.py A · data model
├── config.py A · global config
├── data/template.csv A · data template
│
├── selekt/ B · full pipeline
│ ├── install.sh one-click deploy (Unix)
│ ├── start.sh / stop.sh / restart.sh
│ ├── license.py licence module (env-gated, off by default)
│ ├── selekt-frontend/ analysis backend :8002 + 7-page SPA
│ ├── shopee-backend/ capture backend :8000 + Playwright + scheduler
│ └── shopee-collector/ capture extension (MV3)
│
├── .github/workflows/ Pylint
└── README.md
| Layer | Technology | Purpose |
|---|---|---|
| Capture | Chrome Extension MV3 | in-browser data capture |
| Injection | chrome.scripting API |
attach to SSR pages before render |
| Crawling | Playwright (Python) | headless browser fallback |
| Analysis API | FastAPI + SQLite | scoring, profit modelling, dashboard API |
| Capture API | FastAPI + aiosqlite + APScheduler | job scheduling, SSE progress streaming |
| Dashboard | vanilla HTML/CSS/JS + Chart.js | 7-page single-file SPA |
| Data formats | CSV / XLSX / SQLite | Excel / WPS compatible |
| Licensing | HMAC-SHA256 keys | 3-day trial + permanent keys |
selekt/license.py contains no hard-coded secret. It reads from the environment:
export SELEKT_LICENSE_SECRET="<your-secret>"
# generate one
python -c "import secrets;print(secrets.token_urlsafe(32))"
# check status / issue a key
python license.py
python license.py key <install_id> [days]- Variable unset → licensing is disabled, every API is allowed, zero-config usage.
- Variable set → 3-day trial enforced; once the trial or key expires, all endpoints except the licence endpoints return
402.
Licence data lives in ~/.selekt/.
Listed honestly so nothing gets misused:
- Automated collection currently only works on the Taiwan site. The capture backend's
pending-tasksendpoint does return each job'smarket, but the dispatcher (background.js) does not yet write it into the URL, so automated runs always hitshopee.tw. The manual popup is also gated toshopee.tw. - The extension's price parsing fails on some markets. The price regex in
selekt/shopee-collector/content.jskeys on the dollar sign, so Indonesia (Rp), Thailand (฿) and Vietnam (₫) yield no price; its price tiers are also hard-coded to Taiwan ranges and diverge from the backend'smarkets.price_score(). For multi-market capture, preferextension/(Shopee Scout). - Some analysis-side data is demo data.
dashboard/ai_insight,dashboard/ticker,competitors/summary,competitors/price_distribution,trend/*andradar/*are hard-coded mocks and not yet wired to real sources. Everything from the capture backend (shopee-backend) is real. - The two SQLite databases are not shipped (ignored in
selekt/.gitignore); tables are created on first run. - Deploy scripts are Unix-only; on Windows start the services manually per the sub-directory READMEs.
- The
price_twdcolumn name is misleading for multi-market data — it actually stores the local-currency price, and non-Taiwan products are written into that same column. Be careful when aggregating across markets.
MIT — Fork, Star and Issues are all welcome.
For commercial enquiries, please open a GitHub Issue.
Originally built for a community of 200+ cross-border sellers.
Show, don't just tell. This is not a theoretical project — it is a production toolkit that runs daily in real e-commerce work.