weixin-article-exporter-cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +234 -0
  3. package/index.mjs +1143 -0
  4. package/package.json +37 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 wisdom12333
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,234 @@
1
+ # weixin-article-exporter-cli
2
+
3
+ 微信公众号历史文章列表同步、JSON 导出与 HTML 下载工具。项目为独立 Node.js CLI,不依赖 Nuxt 服务端,也不需要启动 Web 应用。
4
+
5
+ ## 项目来源与免责声明
6
+
7
+ 本项目基于 [wechat-article/wechat-article-exporter](https://github.com/wechat-article/wechat-article-exporter) 进行二次开发,将其中与微信公众号文章获取相关的能力拆分并改造为独立 CLI。感谢原项目作者及贡献者的工作。
8
+
9
+ 本项目是社区开发的非官方工具,与微信、腾讯及微信公众平台不存在隶属、授权或合作关系。项目调用的部分微信公众平台内部接口没有公开稳定性承诺,其可用性、参数及返回结构可能随时发生变化。
10
+
11
+ 使用者应遵守微信公众平台规则、文章版权要求及所在地适用法律,仅处理自己有权访问和使用的内容。请勿将本工具用于绕过访问限制、批量侵权转载或其他未经授权的用途。因使用本项目产生的账号、数据、版权或其他风险由使用者自行承担。
12
+
13
+ ## 功能
14
+
15
+ - 扫码登录微信公众平台并保存本地登录态
16
+ - 搜索公众号并维护同步列表
17
+ - 增量或全量同步公众号历史文章索引
18
+ - 按公众号分组导出 JSON
19
+ - 根据文章 ID 或 URL 下载静态 HTML
20
+ - 清除指定公众号或全部公众号的同步索引
21
+
22
+ ## 环境要求
23
+
24
+ - Node.js 20 或更高版本
25
+ - 可访问 `mp.weixin.qq.com`
26
+ - 一个可以扫码确认的微信公众平台账号
27
+
28
+ CLI 仅使用 Node.js 内置模块,不需要安装运行时依赖。
29
+
30
+ ## 快速开始
31
+
32
+ 在项目目录中直接运行:
33
+
34
+ ```bash
35
+ node index.mjs --help
36
+ node index.mjs --status
37
+ ```
38
+
39
+ 注册为本机命令:
40
+
41
+ ```bash
42
+ npm link
43
+ weixin-article-exporter --help
44
+ ```
45
+
46
+ 解除本机命令:
47
+
48
+ ```bash
49
+ npm unlink -g weixin-article-exporter-cli
50
+ ```
51
+
52
+ ## 常用流程
53
+
54
+ ```bash
55
+ # 1. 扫码登录,默认在支持的终端中显示二维码并同时保存文件
56
+ weixin-article-exporter --login
57
+
58
+ # 2. 搜索公众号,方向键选择,回车添加
59
+ weixin-article-exporter --search "少数派"
60
+
61
+ # 3. 查看已保存公众号
62
+ weixin-article-exporter --list
63
+ weixin-article-exporter --list --list-only --verbose
64
+
65
+ # 4. 同步全部已保存公众号
66
+ weixin-article-exporter --sync
67
+
68
+ # 5. 导出 JSON
69
+ weixin-article-exporter --export --out articles-export.json
70
+
71
+ # 6. 下载文章静态 HTML
72
+ weixin-article-exporter --download "https://mp.weixin.qq.com/s/..."
73
+ ```
74
+
75
+ ## 命令说明
76
+
77
+ ### 登录
78
+
79
+ ```bash
80
+ weixin-article-exporter --status
81
+ weixin-article-exporter --login
82
+ weixin-article-exporter --login --qr terminal
83
+ weixin-article-exporter --login --qr file
84
+ weixin-article-exporter --logout
85
+ ```
86
+
87
+ `--login` 默认使用 `--qr both`:CLI 会从下载的二维码图片中解码出登录链接,再用 Unicode 半块字符重新绘制成二维码直接打印在终端里,不依赖 iTerm2/Kitty 等特定终端图形协议,任意终端(包括 SSH 远程会话)都能显示和扫码;同时仍会保存 `qrcode.jpg` 供需要时查看。若图片中未能识别出二维码内容,会回退为仅提示文件路径。
88
+
89
+ ### 公众号列表
90
+
91
+ ```bash
92
+ weixin-article-exporter --search "公众号名称"
93
+ weixin-article-exporter --search "公众号名称" --add 0
94
+ weixin-article-exporter --search "公众号名称" --list-only
95
+
96
+ weixin-article-exporter --list
97
+ weixin-article-exporter --list --list-only
98
+ weixin-article-exporter --list --list-only --verbose
99
+ weixin-article-exporter --remove 0
100
+ ```
101
+
102
+ 交互列表使用上下方向键或 `j` / `k` 移动。搜索结果按回车确认添加;已保存列表按 `d` 移除当前公众号。
103
+
104
+ ### 同步
105
+
106
+ ```bash
107
+ # 所有公众号默认增量同步
108
+ weixin-article-exporter --sync
109
+
110
+ # 只同步列表 ID 为 0 的公众号
111
+ weixin-article-exporter --sync --id 0
112
+
113
+ # 也可以使用 fakeid
114
+ weixin-article-exporter --sync --fakeid "Mz...=="
115
+
116
+ # 忽略本地增量边界,重新获取最新 1000 篇
117
+ weixin-article-exporter --sync --id 0 --full
118
+
119
+ # 同步到指定日期后停止
120
+ weixin-article-exporter --sync --since 2024-01-01
121
+ ```
122
+
123
+ 同步规则:
124
+
125
+ - 有本地数据时默认增量同步,从最新页开始,遇到一整页已存在文章后停止。
126
+ - 首次同步和 `--full` 单次最多处理每个公众号最新 1000 篇。
127
+ - `--full` 仍会遵守 `--since`。
128
+ - 同步内容是文章列表元数据,不包括正文、评论、阅读量和点赞量。
129
+
130
+ ### 清理同步数据
131
+
132
+ ```bash
133
+ weixin-article-exporter --clear --id 0
134
+ weixin-article-exporter --clear --fakeid "Mz...=="
135
+ weixin-article-exporter --clear
136
+ ```
137
+
138
+ `--clear` 只清理文章索引,不移除公众号列表,也不删除已经下载的 HTML。
139
+
140
+ ### 导出
141
+
142
+ ```bash
143
+ weixin-article-exporter --export --out articles-export.json
144
+ weixin-article-exporter --export --from 2024-01-01 --to 2024-12-31 --out articles-2024.json
145
+ ```
146
+
147
+ 导出结果按公众号分组。未指定 `--out` 时输出到 stdout。
148
+
149
+ ### 下载 HTML
150
+
151
+ ```bash
152
+ weixin-article-exporter --download "Mz...==:2247483660_1"
153
+ weixin-article-exporter --download "2247483660_1"
154
+ weixin-article-exporter --download "https://mp.weixin.qq.com/s/..."
155
+ weixin-article-exporter --download "https://mp.weixin.qq.com/s/..." --out article.html
156
+ weixin-article-exporter --download "https://mp.weixin.qq.com/s/..." --raw
157
+ ```
158
+
159
+ 默认下载模式会对普通图文进行静态化:显示 `#js_content`、激活懒加载图片、修正协议相对资源,并移除微信运行脚本。`--raw` 保存微信返回的原始页面源码。
160
+
161
+ 图片分享(`item_show_type=8`)等动态页面没有 `#js_content`,`--download` 的静态化逻辑目前仍只针对普通图文;这类文章的文字说明可以用下面的 `--download-all` 提取为 Markdown。
162
+
163
+ ### 批量下载为纯文字 Markdown
164
+
165
+ ```bash
166
+ weixin-article-exporter --download-all --id 0
167
+ weixin-article-exporter --download-all --fakeid Mz...== --limit 20
168
+ weixin-article-exporter --download-all --limit 30 --delay 3
169
+ ```
170
+
171
+ `--download-all` 面向"喂给 Agent 做总结"这类自动化场景:只提取正文并转换成纯文字 Markdown(丢弃图片、脚本、样式),不做 HTML 静态化。
172
+
173
+ - 普通图文优先提取 `#js_content`;图片分享(`item_show_type=8`)等没有 `#js_content` 的动态页面,会退而解析页面内嵌的 `window.desc` 图文说明文本(反转义并按段落重排),两者都失败才判定为"未找到正文内容"跳过。
174
+ - 不加 `--id`/`--fakeid` 时会跨所有公众号按发布时间取最新的未下载文章,但总数仍然按 `--limit`(默认 50)封顶,不会因为公众号数量多而放大成百上千个请求,避免触发微信风控。
175
+ - 每篇下载成功后立即把 `downloadedAt` 写回 `articles.json` 并落盘,下次运行会自动跳过已下载文章,只处理剩余/新增的部分;下载失败的文章不会被标记,会在下次运行时重新尝试。
176
+ - `--sync` 增量/全量重新同步不会清除已有的 `downloadedAt` 标记。
177
+
178
+ ## 数据目录
179
+
180
+ 默认数据目录:
181
+
182
+ ```text
183
+ ~/.weixin-article-exporter-cli/
184
+ ├── auth.json
185
+ ├── accounts.json
186
+ ├── articles.json
187
+ ├── qrcode.jpg
188
+ ├── html/
189
+ └── md/
190
+ ```
191
+
192
+ - `auth.json`:登录 Cookie、token 和登录账号信息
193
+ - `accounts.json`:已添加公众号
194
+ - `articles.json`:按 fakeid 分组的文章索引(含每篇文章的 `downloadedAt` 下载标记)
195
+ - `qrcode.jpg`:最近一次登录二维码
196
+ - `html/`:`--download` 下载的文章 HTML
197
+ - `md/`:`--download-all` 下载的纯文字 Markdown
198
+
199
+ 通过环境变量覆盖数据目录:
200
+
201
+ ```bash
202
+ WAE_CLI_HOME=/path/to/data weixin-article-exporter --status
203
+ ```
204
+
205
+ 复用原项目数据,无需复制:
206
+
207
+ ```bash
208
+ WAE_CLI_HOME=/Users/wisdom/Documents/project.nosync/wechat-article-exporter/cli/.data \
209
+ weixin-article-exporter --list --list-only
210
+ ```
211
+
212
+ 也可以把原数据复制到新的默认目录:
213
+
214
+ ```bash
215
+ cp -R /Users/wisdom/Documents/project.nosync/wechat-article-exporter/cli/.data \
216
+ ~/.weixin-article-exporter-cli
217
+ ```
218
+
219
+ 不要把数据目录提交到版本库,其中包含登录凭据和抓取数据。
220
+
221
+ ## 接口边界
222
+
223
+ 文章列表来自微信公众平台内部接口 `/cgi-bin/appmsgpublish`。它只能返回当前登录状态和权限下可见的文章,不保证包含草稿、已删除、受限或接口不再返回的内容。接口没有公开稳定性承诺,参数和返回结构可能变化。
224
+
225
+ 请合理设置请求频率;使用约束与责任说明参见上方“项目来源与免责声明”。
226
+
227
+ ## 开发
228
+
229
+ ```bash
230
+ npm run check
231
+ node index.mjs --help
232
+ ```
233
+
234
+ 项目刻意保持单文件和零运行时依赖。修改接口解析或登录流程后,应至少验证登录状态、搜索、增量同步、导出和 HTML 下载。