73 lines
1.9 KiB
Markdown
73 lines
1.9 KiB
Markdown
# 红餐网文章增量入库
|
|
|
|
使用 Playwright 真实浏览器读取红餐网移动资讯列表,将文章增量保存到 SQLite。数据库包含文章表和采集运行日志表。
|
|
|
|
## 安装
|
|
|
|
```bash
|
|
cd /path/to/hongcan_ingestor
|
|
python3 -m venv .venv
|
|
source .venv/bin/activate
|
|
pip install -r requirements.txt
|
|
playwright install chromium
|
|
```
|
|
|
|
复制 `.env.example` 为 `.env`,填写阿里云百炼 API Key。Key 只保存在本机,不要提交到 Git。
|
|
|
|
## 运行
|
|
|
|
首次运行或手动测试:
|
|
|
|
```bash
|
|
python3 hongcan_ingest.py --db ./data/hongcan.db --headed
|
|
```
|
|
|
|
每日定时运行:
|
|
|
|
```bash
|
|
python3 hongcan_ingest.py --db ./data/hongcan.db --lookback-days 7
|
|
```
|
|
|
|
查看最近采集结果:
|
|
|
|
```bash
|
|
sqlite3 ./data/hongcan.db \
|
|
"SELECT published_at,title,canonical_url FROM articles WHERE crawl_status='success' ORDER BY published_at DESC LIMIT 20;"
|
|
```
|
|
|
|
crontab 示例(每天 08:10):
|
|
|
|
```cron
|
|
10 8 * * * cd /path/to/hongcan_ingestor && .venv/bin/python hongcan_ingest.py --db ./data/hongcan.db >> ./data/cron.log 2>&1
|
|
```
|
|
|
|
## 增量规则
|
|
|
|
- `canonical_url` 唯一索引,重复运行不会重复插入。
|
|
- 默认回溯最近 7 天,避免文章晚发布或列表加载遗漏。
|
|
- 抓取失败最多重试 3 次,错误保存在 `last_error`。
|
|
- 正文与标题生成 SHA-256 内容指纹。
|
|
- 每次执行情况记录在 `crawl_runs`。
|
|
|
|
如果无头模式被拦截,可先使用 `--headed` 检查是否出现验证码。
|
|
|
|
## 启动文章库前端
|
|
|
|
```bash
|
|
./run_web.sh
|
|
```
|
|
|
|
浏览器打开 `http://127.0.0.1:8766`。前端支持全文关键词搜索、文章详情阅读、原文跳转和千问 AI 分析。分析结果保存在数据库的 `ai_analyses` 表;文章正文未变化时会直接使用缓存。
|
|
|
|
批量分析全部文章:
|
|
|
|
```bash
|
|
python3 batch_ai_analyze.py
|
|
```
|
|
|
|
从近期文章分析中提炼跨文章行业信号:
|
|
|
|
```bash
|
|
python3 extract_industry_signals.py --days 30
|
|
```
|