Skip to content

feat(jd): add JD.com product details adapter#344

Merged
jackwener merged 2 commits intojackwener:mainfrom
Xeron2000:feat/jd-item-adapter
Mar 24, 2026
Merged

feat(jd): add JD.com product details adapter#344
jackwener merged 2 commits intojackwener:mainfrom
Xeron2000:feat/jd-item-adapter

Conversation

@Xeron2000
Copy link
Copy Markdown
Contributor

Summary

Add jd item adapter for fetching JD.com (京东) product details.

Features

  • Product info: title, price, shop name
  • Specifications: brand, model, capacity, energy rating, etc.
  • Images: main product images and detail images

Usage

opencli jd item 100291143898        # Table output
opencli jd item 100291143898 --format json  # JSON output

Example Output

{
  "title": "【美的MGH24PROMAX...",
  "price": "10999.00",
  "shop": "京东自营",
  "specs": {
    "品牌": "美的(Midea)",
    "型号": "MGH24PROMAX-W(G)+MGH24PROMAX-W(H)",
    "洗涤容量": "12kg",
    "烘干容量": "12kg",
    ...
  }
}

Test Plan

  • Build succeeds: npm run build
  • Adapter registered in manifest (333 entries)
  • Tested with SKU 100291143898

Xeron2000 and others added 2 commits March 24, 2026 15:31
Support fetching:
- Product title, price, shop
- Product specifications (品牌, 型号, 规格参数 etc.)
- Main product images
- Detail images from product page

Usage: opencli jd item <sku>
- Wire the `images` arg to control mainImages/detailImages slice count
  (was hardcoded to 10, ignoring the arg entirely)
- Add item.test.ts verifying command registration shape
@jackwener jackwener force-pushed the feat/jd-item-adapter branch from be3294b to 8e76039 Compare March 24, 2026 07:36
@jackwener
Copy link
Copy Markdown
Owner

Review

整体方向好,JD 商品详情的 adapter 实现合理。我推了一个修复 commit:

修复

  1. images arg 未生效 — 定义了 images 参数(默认 10),但代码里硬编码了 .slice(0, 10),完全忽略用户传入的值。已修复:通过 maxImg 变量传入 evaluate
  2. 补充测试 — 添加 item.test.ts 验证 command 注册 shape(site、name、domain、strategy、args、columns)。

其他观察(非阻塞)

  • page.wait(2) / page.wait(1) 硬编码等待时间在不同网络环境下可能不够稳定,但对于京东这类重 JS 页面属于常见做法
  • 规格参数通过 innerText 行对提取比较脆弱,如果京东改版可能需要更新,但目前能用
  • shop fallback 到 '京东自营' 不一定准确(第三方店铺页面如果 .J-shop-name 选择器失败),但作为 fallback 可接受

验证

  • npm run typecheck
  • npm test (223 tests) ✅
  • npm run build (334 entries) ✅

可以合入。感谢 @Xeron2000 的贡献!

@jackwener jackwener merged commit 7c808fd into jackwener:main Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants