Files
YTScraper/README.md
T
2026-07-05 13:21:51 +08:00

129 lines
2.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 一堂文档采集工具
采集一堂创业课飞书文档,转换为带本地图片的 Markdown 文件。
## 工具说明
| 工具 | 适用场景 |
|---|---|
| `feishu-to-md.mjs` | 飞书 wiki 链接(`feishu.cn/wiki/...` |
| `auto-scrape.mjs` | 一堂课平台链接(`yitang.top/fs-doc/...` |
---
## 环境准备
### 1. 安装 Node.js 依赖
```bash
npm install
```
### 2. 安装飞书 CLI
```bash
npm install -g @larksuite/cli
```
### 3. 配置飞书 CLI(首次)
```bash
# 初始化 App ID 和 Secret
echo "<your_app_secret>" | lark-cli config init \
--app-id <your_app_id> \
--app-secret-stdin \
--brand feishu
# 发起个人授权(wiki + docs + drive 权限)
lark-cli auth login --domain wiki,docs,drive --no-wait --json
# → 复制输出中的 verification_url,在浏览器中完成扫码授权
# → 授权完成后执行:
lark-cli auth login --device-code <上一步输出的 device_code>
```
---
## 采集飞书 wiki 文档
```bash
node feishu-to-md.mjs <wiki_url>
```
**示例:**
```bash
node feishu-to-md.mjs https://yitanger.feishu.cn/wiki/R9NywV2i9izjuqkPd63cWuafn4g
```
**输出:**
- `output/<文档标题>.md` — Markdown 正文
- `output/<文档标题>_files/` — 本地图片目录(PNG 格式)
图片以相对路径引用,可在 Obsidian、Typora 等编辑器中离线展示。
**自定义输出目录:**
```bash
node feishu-to-md.mjs <wiki_url> ./my-docs
```
---
## 采集一堂课平台文档
```bash
node auto-scrape.mjs <url>
```
**示例:**
```bash
node auto-scrape.mjs https://yitang.top/fs-doc/abc123/docId
```
首次运行会弹出浏览器,完成微信扫码或手机验证码登录后,Cookie 自动保存,后续无需重复登录。
**输出:** `output/<文档标题>.md`
---
## 文件结构
```
scraper/
├── feishu-to-md.mjs # 飞书 wiki 采集工具
├── auto-scrape.mjs # 一堂课平台采集工具
├── cookies.json # yitang.top 登录 cookie(自动生成)
├── feishu-cookies.json # 飞书 cookie(自动生成)
├── package.json
└── output/ # 所有输出文档
├── 文档标题.md
└── 文档标题_files/
├── image_1.png
└── ...
```
---
## 常见问题
**Q: 飞书采集提示未登录或 401?**
重新授权:
```bash
lark-cli auth login --domain wiki,docs,drive --no-wait --json
```
**Q: 一堂课平台 Cookie 失效?**
删除 `cookies.json` 后重新运行,会自动弹出浏览器重新登录:
```bash
rm cookies.json
node auto-scrape.mjs <url>
```
**Q: 图片下载失败?**
飞书图片需要有效的个人授权。确认 `lark-cli auth status` 显示已登录,且包含 `docs:document.media:download` 权限。