Skip to content

增加新浪财经热搜股票榜#736

Merged
jackwener merged 2 commits intojackwener:mainfrom
yichuanzhao99-ctrl:sinafinance-hot-stock-rank
Apr 4, 2026
Merged

增加新浪财经热搜股票榜#736
jackwener merged 2 commits intojackwener:mainfrom
yichuanzhao99-ctrl:sinafinance-hot-stock-rank

Conversation

@yichuanzhao99-ctrl
Copy link
Copy Markdown
Contributor

Description

Add sinafinance stock-rank command - 新浪财经热搜榜

新增 stock-rank 命令,支持抓取新浪财经移动端首页股票热搜榜数据:

  • 支持多个市场的股票热搜榜:A股(cn)、港股(hk)、美股(us)、外汇(wh)、期货(ft)

同时更新了 docs/adapters/browser/sinafinance.md 文档。

Type of Change

  • ✨ New feature
  • 📝 Documentation

Checklist

  • Added doc page under docs/adapters/ (updated existing sinafinance.md)
  • Used positional args for the command's primary subject (uses --market flag for market selection)

Screenshots / Output

# A股热搜榜
$ opencli sinafinance stock-rank
Column | Name    | Symbol  | Market | Price  | Change | Url
-------+---------+---------+--------+--------+--------+-----
1      | 贵州茅台 | 600519  | A股    | 1850.0 | +2.3%  | https://finance.sina.com.cn/...

# 港股热搜榜
$ opencli sinafinance stock-rank --market hk

# 期货热搜榜
$ opencli sinafinance stock-rank --market ft

# 外汇热搜榜
$ opencli sinafinance stock-rank --market wh

# 美股热搜榜
$ opencli sinafinance stock-rank --market us

Copy link
Copy Markdown
Owner

@jackwener jackwener left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review

Good feature direction — stock ranking data from Sina Finance is useful. A few issues need fixing before merge:

1. Security: String interpolation injection in evaluate

const marketType = '${market}';

User input is directly interpolated into the evaluate string. Use JSON.stringify:

const marketType = ${JSON.stringify(market)};

2. Missing market validation

Add choices to the arg definition to restrict valid values:

{ name: 'market', type: 'string', default: 'cn', choices: ['cn', 'hk', 'us', 'wh', 'ft'], help: '...' }

3. Column names inconsistent with other sinafinance commands

Other commands use lowercase (title, date, url). This PR uses PascalCase (Column, Name, Price). Please use lowercase: rank, name, symbol, market, price, change, url.

4. Unrelated change in rolling-news.ts

The ?from=opencli URL tracking change is unrelated to stock-rank and modifies existing output. Please remove it from this PR.

5. Null safety on tabEl

const tabEl = document.querySelector('[data-type="' + marketType + '"]');
const marketName = tabEl.textContent; // tabEl may be null

Use optional chaining: tabEl?.textContent || marketType

6. Add navigateBefore: false

The func already calls page.goto(), so the framework's pre-navigation is redundant. Add navigateBefore: false to avoid double navigation.

- Fix string interpolation injection: use JSON.stringify for market param
- Add choices validation for market arg (cn/hk/us/wh/ft)
- Normalize column names to lowercase (rank/name/symbol/market/price/change/url)
- Add navigateBefore: false to avoid redundant navigation
- Add null safety on tabEl with optional chaining
- Remove unused waitForElement helper and unnecessary await on querySelectorAll
- Remove unrelated ?from=opencli tracking change from rolling-news.ts
- Remove ?from=opencli tracking from stock-rank URLs
Copy link
Copy Markdown
Owner

@jackwener jackwener left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All review issues fixed. LGTM.

@jackwener jackwener merged commit 8eefa3b into jackwener:main Apr 4, 2026
11 checks passed
just-buer pushed a commit to just-buer/opencli that referenced this pull request Apr 8, 2026
* 增加新浪财经热搜股票榜

* fix: address review issues in stock-rank adapter

- Fix string interpolation injection: use JSON.stringify for market param
- Add choices validation for market arg (cn/hk/us/wh/ft)
- Normalize column names to lowercase (rank/name/symbol/market/price/change/url)
- Add navigateBefore: false to avoid redundant navigation
- Add null safety on tabEl with optional chaining
- Remove unused waitForElement helper and unnecessary await on querySelectorAll
- Remove unrelated ?from=opencli tracking change from rolling-news.ts
- Remove ?from=opencli tracking from stock-rank URLs

---------

Co-authored-by: jackwener <jakevingoo@gmail.com>
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