2026-07-19 18:11:08 +08:00
2026-07-19 18:11:08 +08:00
2026-07-19 18:11:08 +08:00
2026-07-19 18:11:08 +08:00
2026-07-19 18:11:08 +08:00
2026-07-19 18:11:08 +08:00
2026-07-19 18:11:08 +08:00
2026-07-19 18:11:08 +08:00
2026-07-19 18:11:08 +08:00
2026-07-19 18:11:08 +08:00

红餐网文章增量入库

使用 Playwright 真实浏览器读取红餐网移动资讯列表,将文章增量保存到 SQLite。数据库包含文章表和采集运行日志表。

安装

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。

运行

首次运行或手动测试:

python3 hongcan_ingest.py --db ./data/hongcan.db --headed

每日定时运行:

python3 hongcan_ingest.py --db ./data/hongcan.db --lookback-days 7

查看最近采集结果:

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):

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 检查是否出现验证码。

启动文章库前端

./run_web.sh

浏览器打开 http://127.0.0.1:8766。前端支持全文关键词搜索、文章详情阅读、原文跳转和千问 AI 分析。分析结果保存在数据库的 ai_analyses 表;文章正文未变化时会直接使用缓存。

批量分析全部文章:

python3 batch_ai_analyze.py

从近期文章分析中提炼跨文章行业信号:

python3 extract_industry_signals.py --days 30
S
Description
红餐文章本地研究工具 - SQLite + Playwright + Qwen
Readme 1.4 MiB
Languages
Python 75.9%
HTML 17.8%
JavaScript 5.5%
CSS 0.6%
Shell 0.2%