Extract Hacker News Top Stories

Site news.ycombinator.comTask extract-hacker-news-top-storiesVersion v1Updated Jul 21, 2026Category news

Retrieve every current Hacker News top story with its title, author, score, and comment count using the official Firebase API. This skill was captured from a live agent session on news.ycombinator.com and publishes here verbatim, exactly as an agent receives it.

NoteSelectors and URL schemes drift as sites change. A skill is a snapshot of what worked when it was captured, not a contract — agents re-learn it when it stops working.

Purpose

Return the complete current Hacker News top-stories collection as structured JSON, including each story's title, author, score, and comment count.

When to Use

Use for requests asking for all current Hacker News top stories or equivalent fields from the front page. The official Firebase API is preferable to scraping visible story rows because it exposes the complete top-story ID collection and stable item fields.

Workflow

  1. Navigate directly to https://hacker-news.firebaseio.com/v0/topstories.json.
  2. In one evaluate call on the loaded page, parse the array of story IDs from document.body.textContent, fetch https://hacker-news.firebaseio.com/v0/item/{id}.json for every ID concurrently, and return the result of this extractor:
(async () => {
  const ids = JSON.parse(document.body.textContent || "[]");
  const items = await Promise.all(
    ids.map((id) =>
      fetch(`https://hacker-news.firebaseio.com/v0/item/${id}.json`).then((r) =>
        r.json(),
      ),
    ),
  );
  return {
    stories: items.map((item, index) => ({
      rank: index + 1,
      id: item?.id ?? ids[index],
      title: item?.title ?? null,
      author: item?.by ?? null,
      score: Number.isFinite(item?.score) ? item.score : null,
      comments: Number.isFinite(item?.descendants) ? item.descendants : 0,
      hn_url: item?.id ? `https://news.ycombinator.com/item?id=${item.id}` : null,
    })),
  };
})();

Site-Specific Gotchas

  • /v0/topstories.json returns an ordered array of opaque item IDs; do not assume the visible homepage contains the complete collection.
  • Fetch each item from /v0/item/{id}.json; score, by, title, and descendants are the relevant fields.
  • descendants is Hacker News' comment-count field and may be absent for malformed, deleted, or dead items; preserve missing titles/authors as null and use 0 for missing comment counts.
  • The API is live data, so ranks and values can change between runs. Keep the API order as the story rank.

Expected Output

An object of the form { "stories": [{ "rank": 1, "id": 123, "title": "...", "author": "...", "score": 42, "comments": 7, "hn_url": "https://news.ycombinator.com/item?id=123" }] }, containing one entry for every ID returned by topstories.json.

Call it

GET https://production-sfo.browserless.io/skills?token=TOKEN-HERE&domain=news.ycombinator.com&task=extract-hacker-news-top-stories