> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.beatapi.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.beatapi.io/_mcp/server.

# 怎样把关注的公众号和小红书选题加入 TrendRadar？

> 把两类审核过的内容分别生成 RSS，接入 TrendRadar 并核对抓取、筛选和报告。

在 TrendRadar 的 `config/config.yaml` 里，给 `rss.feeds` 加两个订阅：一个放公众号新文章，一个放小红书选题。先用 BeatAPI 取账号列表或搜索结果，再把入选内容生成 RSS 文件（小红书用下面的 `make_feed.py`），把每个 RSS 文件发布到 TrendRadar 能访问的 HTTPS 地址。先加第一个源，确认一条样例进了 TrendRadar 日报，再加第二个。

## 准备两个可访问的源

* **公众号**：用[公众号增量检查](/zh/guides/wechat-incremental-articles)建立候选清单。有已保存正文的精选文章，可直接复用[本地 RSS 生成器](/zh/guides/wechat-to-rss)。
* **小红书**：用[笔记搜索导出](/zh/guides/xiaohongshu-notes-research)得到笔记 ID、标题和搜索摘录，用导出表选文。为每条已选笔记另存一条实际核对过的作品链接，已保存材料不够用时再取笔记详情。

只按标题与链接制作订阅时，复用已保存材料即可，不需要补每篇正文。在自己的 RSS 发布流程里：

1. 每个来源生成一个 XML 文件。
2. 每条含真实的 `title`、`link` 和稳定的 `guid`：公众号用账号与文章键，小红书用笔记 ID，两个来源用不同前缀。搜索重跑再次看到同一条帖子时，沿用原来的 `guid`。
3. `description` 写已保存的摘录。
4. 只有确实知道发布时间时才写 `pubDate`，按 RSS 时间格式输出。
5. 用一条真实条目验收后，把 XML 文件放到 TrendRadar 运行环境能访问的 HTTPS 地址。

## 用已审核的清单生成小红书 RSS

把已审核的条目整理为 `notes.json`。`link` 是订阅源首页，`items[].url` 是逐条核对过的原帖链接。知道发布时间时，`published_at` 写带时区的 ISO 8601 时间，不知道就省略。把示例里的标题、链接和 ID 换成自己的。

```json
{
  "title": "Coffee notes",
  "link": "https://feeds.example.com/",
  "description": "Reviewed Xiaohongshu research leads",
  "items": [
    {
      "id": "xiaohongshu:example-note",
      "title": "Coffee equipment cleaning",
      "url": "https://example.com/original-note",
      "excerpt": "Saved excerpt"
    }
  ]
}
```

```python
import json
import sys
import tempfile
from datetime import datetime
from email.utils import format_datetime
from pathlib import Path
from urllib.parse import urlsplit
from xml.etree import ElementTree as ET

source, target = map(Path, sys.argv[1:])
data = json.loads(source.read_text(encoding="utf-8"))
rss = ET.Element("rss", version="2.0")
channel = ET.SubElement(rss, "channel")
for field in ("title", "link", "description"):
    value = data[field].strip()
    if not value:
        raise SystemExit(f"Missing channel {field}")
    ET.SubElement(channel, field).text = value

seen = set()
for row in data["items"]:
    item_id, title, link = (row[key].strip() for key in ("id", "title", "url"))
    url = urlsplit(link)
    if not item_id or not title or url.scheme != "https" or not url.hostname or url.username:
        raise SystemExit("Provide a stable ID, title and verified HTTPS link")
    if item_id in seen:
        raise SystemExit(f"Duplicate item ID: {item_id}")
    seen.add(item_id)
    item = ET.SubElement(channel, "item")
    ET.SubElement(item, "title").text = title
    ET.SubElement(item, "link").text = link
    ET.SubElement(item, "guid", isPermaLink="false").text = item_id
    if row.get("excerpt"):
        ET.SubElement(item, "description").text = row["excerpt"]
    if row.get("published_at"):
        published = datetime.fromisoformat(row["published_at"].replace("Z", "+00:00"))
        if published.utcoffset() is None:
            raise SystemExit(f"Missing timezone for {item_id}")
        ET.SubElement(item, "pubDate").text = format_datetime(published)

if not seen:
    raise SystemExit("Empty feed; previous file kept")
xml = ET.tostring(rss, encoding="utf-8", xml_declaration=True)
ET.fromstring(xml)
with tempfile.NamedTemporaryFile(dir=target.parent, delete=False) as temp:
    temporary_path = Path(temp.name)
try:
    temporary_path.write_bytes(xml)
    temporary_path.replace(target)
finally:
    temporary_path.unlink(missing_ok=True)
```

将脚本保存为 `make_feed.py`，用 Python 3.8+ 运行 `python3 make_feed.py notes.json xiaohongshu.xml`。新 XML 通过解析后，`make_feed.py` 才替换 `xiaohongshu.xml`。空清单、重复 ID 或无效日期会保留旧的 `xiaohongshu.xml`；修正 `notes.json` 后在本地重跑 `make_feed.py`。

## 在 TrendRadar 中添加订阅

把下面两项合并到部署所用 `config/config.yaml` 的 `rss.feeds` 列表，保留 `rss.feeds` 里已有的其他订阅，并替换示例地址。容器内的 `localhost` 指向 TrendRadar 容器自己，不是宿主机。

```yaml
rss:
  enabled: true
  feeds:
    - id: wechat-research
      name: 公众号研究
      url: https://feeds.example.com/wechat.xml
    - id: xiaohongshu-research
      name: 小红书选题
      url: https://feeds.example.com/xiaohongshu.xml
```

1. 在 TrendRadar 的运行环境里确认每个订阅地址都能读取。
2. 执行一次 TrendRadar，查看抓取日志和报告。
3. 用关键词模式时，把测试条目应命中的词写进 `config/frequency_words.txt`。
4. 核对 `display.regions.rss` 已开启、`display.region_order` 包含 `rss`，再看时间过滤。
5. 分别配置刷新和推送时间，让 RSS 生成任务先完成，TrendRadar 再抓取。

## 没出现在日报里怎么查？

| 现象        | 先检查                             |
| --------- | ------------------------------- |
| 日志无法取源    | URL 可达性、权限和 XML 解析              |
| 已抓取但报告无匹配 | 关键词、RSS 区域、发布时间与 `max_age_days` |
| 同一条反复出现   | 原帖 ID、`guid`、推送模式和重复运行          |
| 日期对不上     | 原始时间单位、时区，以及是否误用了采集日期           |

例如日报只想看「冷萃」，先给测试源放两条同一天发布的记录：《冷萃咖啡入门》和《烤箱清洁指南》。开启关键词筛选并加上「冷萃」后，抓取日志应显示测试源抓取成功，日报应显示《冷萃咖啡入门》和原文链接。两篇都在测试源里、日报却没有《冷萃咖啡入门》时，先查关键词和显示设置。再用同一个 `guid` 重发《冷萃咖啡入门》，确认当前推送模式把这条识别为旧条目。

新一轮没有入选笔记时，`make_feed.py` 保留上一份 XML。给生成任务留一条日志，记下源名、生成时间和本轮结果，例如「小红书选题，周二 09:00，无入选，沿用周一版本」。日志显示周二已有新 XML、TrendRadar 却还读到周一的条目时，从 TrendRadar 运行环境核对订阅 URL 实际返回的是哪个文件。修改标题时，沿用同一个笔记 ID 和 `guid`。

每天查 5 个公众号和 3 个小红书关键词，各取一页就是 8 次数据请求。用已保存记录重建 XML 不需要重新查询。翻页和笔记详情按实际请求数计费。 [BeatAPI 价格页](https://beatapi.io/zh/pricing)

[TrendRadar RSS 配置样例](https://github.com/sansan0/TrendRadar/blob/master/config/config.en.yaml) · [TrendRadar 关键词及订阅说明](https://github.com/sansan0/TrendRadar/blob/master/README-EN.md) · [RSS 2.0 规范](https://www.rssboard.org/rss-specification)