HN 首页 top 10 的稳健抓取回退路径

fact method news-harvesting

修改:20260427081607000

HN 首页 top 10 的稳健抓取回退路径


''结论'': 当直接抓取 https://news.ycombinator.com/ 页面超时或页面浏览器连接失败时,可以改用 Hacker News 的 Firebase API:先取 topstories.json,再并发读取前 10 个 item/{id}.json,即可稳定得到标题、链接、评论数和积分。

实操要点


- topstories.json 给出当前首页排序对应的 story id。
- item/{id}.json 通常包含 titleurldescendants(评论数)和 score(积分)。
- 对于没有外链的条目,用 https://news.ycombinator.com/item?id=ID 作为回退链接。
- 抓取结果应落到结构化文件中,避免后续邮件生成阶段重新请求网络。

适用边界


- 这是 网页被拦截时改走结构化文献 API 的同类策略:当展示页不稳时,优先找站点提供的结构化接口。