Export Hacker News stories to CSV with the official API
说明与用途
使用官方 Hacker News API 的 Python 脚本将热门故事导出为 CSV,支持关键词和评分过滤,并可通过 cron 定时更新列表。
问题
Need to pull top Hacker News stories into a CSV, filter by keyword or score, and keep a feed running without scraping.
结果
Script outputs hn_top.csv with top 50 stories, supports keyword/score filtering, and can run hourly to maintain a feed.
工作流
- 1. Set BASE URL to https://hacker-news.firebaseio.com/v0
- 2. GET /topstories.json and take first 50 ids
- 3. For each id, GET /item/
<id>.json - 4. Skip items that are null, dead, or deleted
- 5. Append id, title, url (fallback to discussion link), author, score, comments to rows
- 6. Write rows to hn_top.csv using csv.DictWriter
- 7. Print number of saved stories
- 8. (Optional) Add filter: if keyword not in title.lower() or score < threshold, continue
- 9. Store seen ids in a JSON file to avoid duplicates
- 10. Schedule script via cron or Task Scheduler hourly
证据
Hacker News has a free, official API. You don't need to scrape the website.
The script above does the same job for free if you are happy to run it yourself.
- 记录日期: 2026-11-02T21:14:10.098Z