Files
py-chan/README.md
2026-08-11 16:18:44 +08:00

45 lines
1.6 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.
# py-chan · 缠论《教你炒股票》抓取器
抓取 [kline8.com/chanlun](https://www.kline8.com/chanlun?p=0) 上缠中说禅
《教你炒股票》系列全部 108 课原文,转换为结构化数据,并直接写入 Vue 阅读站
[`D:\code\chan`](../chan),在 `http://localhost:5173/chanlun` 展示。
> `p=0` 是目录页,`p=1`…`p=108` 依次对应第 1108 课。
## 依赖
```bash
pip install -r requirements.txt
```
## 使用
```bash
python main.py # 全量抓取(带缓存,可重复运行)
python main.py --limit 3 # 仅抓前 3 篇,联调测试
python main.py --refresh # 忽略缓存重新抓取
python main.py --no-images # 不下载图片,正文保留远程链接
```
## 产物
| 路径 | 说明 |
| --- | --- |
| `data/raw/p001.html …` | 原始 HTML 归档 |
| `data/markdown/ke-001.md …` | 每篇 Markdown 归档 |
| `data/articles.json` | 全量结构化数据 |
| `D:\code\chan\src\data\chanlun.ts` | Vue 数据源(首次运行会自动备份示例为 `chanlun.sample.ts` |
| `D:\code\chan\public\chanlun-img\…` | 本地化图片 |
## 模块
- `config.py` —— 站点、请求、产物路径等常量
- `fetcher.py` —— 带限速 / 重试 / SSL 回退的 HTTP 抓取
- `parser.py` —— 目录页与文章页解析,产出 `Article` 结构
- `converter.py` —— 正文 HTML → Markdown含行内样式与图片
- `writer.py` —— 图片本地化、TS 数据文件、JSON 输出
- `main.py` —— 命令行入口与编排
抓取后到 `D:\code\chan` 运行 `pnpm dev`,访问 `http://localhost:5173/chanlun`
即可看到全部 108 课;点击任意一篇进入沉浸式阅读页。