npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

xianyu-query

v0.2.0

Published

一个基于用户提供 Cookie 的闲鱼关键词查询 CLI,支持登录会话导入、搜索、导出与退出。

Downloads

23

Readme

2-taobao-query-skills

一个基于用户提供基础 Cookie 的闲鱼关键词查询 CLI。

功能说明

  • 支持导入用户从闲鱼网页拿到的基础 Cookie
  • 自动把可用会话保存到 session.json
  • 自动通过 mtop.gaia.nodejs.gaia.idle.data.gw.v2.index.get 补齐 _m_h5_tk / _m_h5_tk_enc
  • 在查询时直接用 Node 请求闲鱼搜索接口,不依赖浏览器自动化
  • 支持 login / query / export / logout
  • 支持单关键词、多关键词、完整结果和 CSV / JSON 导出

安装

本地开发直接运行:

node ./bin/2-taobao-query-skills.cjs --help

发布到 npm 后可以直接使用:

npm install -g xianyu-query
xianyu-query --help

发布前建议

先本地执行:

npm test

然后按常规 npm 流程发布:

npm version patch
npm publish

如果只是本地调试 CLI:

npm run cli -- --help

命令列表

xianyu-query login --cookie '<cookie>' [--session session.json] [--query codex] [--raw] [--json]
xianyu-query query [--cookie '<cookie>'] [--session session.json] [--full] [--raw] [--csv|--json|--pretty] <关键词...>
xianyu-query export [--cookie '<cookie>'] [--session session.json] --output results.csv [--full] [--raw] [--csv|--json|--pretty] <关键词...>
xianyu-query logout [--session session.json]
xianyu-query <关键词...>

首次初始化会话

如果本地还没有可用会话,先在浏览器打开:

https://www.goofish.com/search?q=codex&spm=a21ybx.search.searchInput.0

然后把页面里的基础 Cookie 传给 CLI。这里不要求你手工带上 _m_h5_tk / _m_h5_tk_enc,CLI 会在首次请求时自动补齐:

xianyu-query login \
  --cookie '<document.cookie 或请求头 cookie>' \
  --query codex

执行成功后,会自动生成并刷新本地 session.json。默认只输出:

登录成功

后续查询一般不需要再次提供 Cookie。

基础 Cookie 说明

通常下面这些基础字段已经足够完成自举:

  • cookie2
  • cna
  • t
  • _tb_token_
  • tfstk

其他账号态字段如果有,也建议一并传入。

不需要你手动准备:

  • _m_h5_tk
  • _m_h5_tk_enc
  • mtop_partitioned_detect

这些会由脚本在首次 bootstrap 时自动拿到并写入本地会话。

常用用法

单关键词查询:

xianyu-query codex

或者显式写法:

xianyu-query query codex

多关键词查询:

xianyu-query query \
  小红薯 business 酒店

输出第一页全部结果:

xianyu-query query --full \
  codex

把结果写入文件:

xianyu-query export \
  --full --output results.csv \
  小红薯 business 酒店

使用单独的会话文件:

xianyu-query query \
  --session /tmp/2taobaoquery-session.json \
  codex

退出并删除本地会话:

xianyu-query logout --session /tmp/2taobaoquery-session.json

返回内容

默认输出为 CSV 文本,更适合终端直接查看。列包括:

  • query
  • pageNumber
  • status
  • numFound
  • searchId
  • rn
  • itemCount
  • itemId
  • categoryId
  • price
  • area
  • title
  • url
  • failure

使用 --full 后,会输出当前第一页的全部 30 条商品;不加时默认输出前 5 条。

如果你要给脚本或其他程序消费输出,可以加:

xianyu-query query --json codex

其中:

  • --csv:CSV 文本,适合终端直接读,默认值
  • --json:单行 JSON,适合脚本读取
  • --pretty:格式化 JSON,适合人工排查

注意事项

  • 默认会话文件是仓库根目录下的 session.json
  • 如果返回 RGV587_ERROR::SM,说明当前基础会话被风控拦截,需要重新导入新的浏览器 Cookie
  • 当前脚本只抓每个关键词的第一页结果,不自动翻页