Skip to content

fix(smzdm): navigate to search results page directly instead of deprecated ajax API#113

Merged
jackwener merged 1 commit intojackwener:mainfrom
ylongw:fix/smzdm-search-dom-scraping
Mar 20, 2026
Merged

fix(smzdm): navigate to search results page directly instead of deprecated ajax API#113
jackwener merged 1 commit intojackwener:mainfrom
ylongw:fix/smzdm-search-dom-scraping

Conversation

@ylongw
Copy link
Contributor

@ylongw ylongw commented Mar 20, 2026

Problem

opencli smzdm search always returns empty results because the old adapter called search.smzdm.com/ajax/?c=<channel>&s=<q> which now returns 404.

Root Cause

The /ajax/ endpoint has been deprecated/removed. Any HTTP request to it (including with credentials) returns 404, so the adapter silently falls through and returns [].

Fix

Navigate directly to the search results page:

https://search.smzdm.com/?c=home&s=<keyword>&v=b

Then scrape li.feed-row-wide elements from the rendered DOM — the same selectors the old adapter used for parsing, so no selector changes needed.

Also simplified from async IIFE (with fetch) to sync IIFE since all data is available in the DOM after page load.

Test

opencli smzdm search --keyword A7M5 --limit 5

Before: []

After:

┌──────┬──────────────────────────────────────────────┬─────────┬────────────┬──────────┬────────────────────────────────────┐
│ Rank │ Title                                        │ Price   │ Mall       │ Comments │ Url                                │
├──────┼──────────────────────────────────────────────┼─────────┼────────────┼──────────┼────────────────────────────────────┤
│ 1    │ 索尼 A7M5/a7V 全画幅微单相机                 │ 16667元 │ 拼多多     │ 2        │ https://www.smzdm.com/p/170164055/ │
│ 2    │ 索尼 Alpha7 V A7M5 新基准全画幅微单相机       │ 17999元 │ 天猫精选   │ 0        │ https://www.smzdm.com/p/170605199/ │
│ 3    │ 索尼 Alpha 7 V 全画幅 无反相机 单机身         │ 17999元 │ 京东       │ 0        │ https://www.smzdm.com/p/170563521/ │
│ 4    │ 索尼 ILCE-7M5 A7M5/a7V 全画幅微单摄影相机    │ 16899元 │ 拼多多     │ 2        │ https://www.smzdm.com/p/169382065/ │

…ax API

The old adapter called `search.smzdm.com/ajax/?c=<channel>&s=<q>` which
now returns 404. This caused opencli smzdm search to always return empty
results regardless of keyword.

Fix: navigate directly to `search.smzdm.com/?c=home&s=<keyword>&v=b`
and scrape the rendered DOM via querySelectorAll('li.feed-row-wide').

Also switched from async IIFE to sync IIFE since all data is already in
the DOM after page load — no fetch needed.

Tested: opencli smzdm search --keyword A7M5 returns correct results
with prices and mall names.
@jackwener jackwener merged commit 812db29 into jackwener:main Mar 20, 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