# Hacker News Comments Scraper: full thread text by story, bulk (`steadydata/hacker-news-comments`) Actor

All comments under Hacker News stories, up to 200 stories per run and up to 2,000 comments each, in thread order with depth and parent: plain text, time, reply count and comment link, plus the story's title, points and URL on every row, from the official Algolia API. No usernames. Pay per comment.

- **URL**: https://apify.com/steadydata/hacker-news-comments.md
- **Developed by:** [Steadydata Team](https://apify.com/steadydata) (community)
- **Categories:** News, Social media, Automation
- **Stats:** 2 total users, 1 monthly users, 75.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.35 / 1,000 comment listeds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Hacker News Comments Scraper: full thread text by story, bulk

All comments under Hacker News stories, up to 200 stories per run and up to 2,000 comments each, in thread order with depth and parent: plain text, time, reply count and comment link, plus the story's title, points and URL on every row, from the official Algolia API. No usernames. Pay per comment.

### Why this scraper

- **Only delivered results are charged.** Inputs that fail come back as clear error
  records at no cost.
- One call per story to the official Hacker News API on Algolia returns the whole comment tree at once. Measured on the platform: 121 comments of two stories in 17 seconds for a quarter of a cent; a 201-comment thread is a single 111 KB response.
- The thread structure survives. Every comment carries its position in reading order, its depth, its parent id, how many direct replies it has and how many comments sit below it in total, so you can rebuild the discussion, take only top-level comments or find the most-discussed branch. The story's title, link, points and total comment count are on every row.
- No usernames. Hacker News handles are people; they are dropped before anything is stored. What you get is what was said, when, and where in the thread.

### Who this is for

Paste Hacker News item ids or item URLs in `stories` (up to 200 per run) and set `maxCommentsPerStory` (default 200, ceiling 2,000). `order` is `thread` (reading order: each top-level comment followed by its replies) or `newest` (flat, most recent first). Built for sentiment and argument mining on launches, incidents and Ask HN threads, for summarising discussions, and for tracking how a story's reception develops.

### Who this is not for

There are no usernames, karma or profile links on purpose, so this is not a tool for finding or profiling commenters. Hacker News does not publish comment scores, so there is no `points` per comment; `replyCount` and `descendantCount` are the only signals of attention. Deleted and dead comments have no text and are skipped (measured: 3 of 24 in one thread), so `storyCommentCount` can be a little higher than the rows delivered. A comment id instead of a story id comes back as a free `INVALID_STORY` error naming the story id to use. Text is flattened to one line; links inside a comment keep their anchor text, not the URL.

### Input example

```json
{
    "stories": [
        "45148944",
        "https://news.ycombinator.com/item?id=45148944"
    ],
    "maxCommentsPerStory": 200,
    "order": "thread"
}
```

### Output example

- `storyId`
- `storyTitle`
- `storyUrl`
- `storyPoints`
- `storyCommentCount`
- `position`
- `commentId`
- `parentId`
- `depth`
- `text`
- `createdAt`
- `replyCount`
- `descendantCount`
- `hnUrl`

Error codes: `INVALID_STORY`, `NOT_FOUND`, `NO_COMMENTS`, `BLOCKED`.

One delivered row looks like this:

```json
{
  "storyId": "45148944",
  "storyTitle": "We hacked Burger King: How auth bypass led to drive-thru audio surveillance",
  "storyUrl": "https://bobdahacker.com/blog/rbi-hacked-drive-thrus/",
  "storyPoints": 427,
  "storyCommentCount": 201,
  "position": 15,
  "commentId": "45149383",
  "parentId": "45148944",
  "depth": 1,
  "text": "Great write-up! I was sorry to see there wasn’t a reward for you reporting this to them. At least you didn’t find that the bathroom rating tablets had audio as well!",
  "createdAt": "2025-09-06T14:08:16.000Z",
  "replyCount": 1,
  "descendantCount": 6,
  "hnUrl": "https://news.ycombinator.com/item?id=45149383",
  "status": "ok"
}
```

### Related actors from steadydata

- [hacker-news-search](https://apify.com/steadydata/hacker-news-search): the stories themselves, to find threads worth reading
- [rss-feed-reader](https://apify.com/steadydata/rss-feed-reader): the same stories as a feed, without the discussion
- [webpage-to-markdown](https://apify.com/steadydata/webpage-to-markdown): the article a thread is about, as clean text

### Pricing

Pay per event: one `comment-listed` event per delivered result. No charge for inputs
that fail, no separate platform-usage surcharge.

**Free Apify plan:** this actor delivers up to 25 rows per run for accounts on the Apify free
plan, and then stops with a message. That limit is set by us, not by Apify. It exists so the
actor keeps paying for itself for the people who do pay. Any paid Apify plan runs it at full
size, billed per delivered row, with failed rows never charged.

**Reviews:** if this actor saves you time, a short review on this page is the one thing that
helps most. Ratings are what other buyers look at first, and we have no other way to ask.

### FAQ

**Is personal data collected?**
No. The commenter's username that the API returns with every comment is dropped before storage; nothing on a row identifies who wrote it.

**How do I rebuild the thread?**
Rows arrive in reading order. `depth` 1 is a top-level comment; a reply has `depth` one higher and `parentId` equal to the comment it answers. `descendantCount` tells you how big each branch is without reading it.

**Can I get the newest comments only?**
Set `order` to `newest`: the same rows, sorted by `createdAt` descending, with `position` renumbered. With `maxCommentsPerStory` set to 50 that is the last fifty comments of the thread.

**What about stories with thousands of comments?**
The ceiling is 2,000 per story; the API returns the whole tree in one response, so even a large thread is one call. Above the ceiling you get the first 2,000 in reading order.

**Does a run cost anything when a story has no comments?**
No. `NO_COMMENTS`, `NOT_FOUND`, `INVALID_STORY` and `BLOCKED` rows are free; only delivered comments are charged.

**What happens when the source changes?**
Sources change from time to time; that is the nature of this work. The actor is
monitored daily and fixed fast, and while it is broken you are not charged, because
only delivered results cost anything.

# Changelog

This Actor's version history is a separate document: https://apify.com/steadydata/hacker-news-comments/changelog.md

# Actor input Schema

## `stories` (type: `array`):

One per row, up to 200: a Hacker News item id (45148944) or an item URL (https://news.ycombinator.com/item?id=45148944).

## `maxCommentsPerStory` (type: `integer`):

Cost ceiling per story, in thread order (top comments first, replies directly under them).

## `order` (type: `string`):

thread (as shown on Hacker News: top-level comments with their replies) or newest (most recent first, flat).

## Actor input object example

```json
{
  "stories": [
    "45148944",
    "https://news.ycombinator.com/item?id=45148944"
  ],
  "maxCommentsPerStory": 200,
  "order": "thread"
}
```

# Actor output Schema

## `results` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "stories": [
        "45148944",
        "https://news.ycombinator.com/item?id=45148944"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("steadydata/hacker-news-comments").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "stories": [
        "45148944",
        "https://news.ycombinator.com/item?id=45148944",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("steadydata/hacker-news-comments").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "stories": [
    "45148944",
    "https://news.ycombinator.com/item?id=45148944"
  ]
}' |
apify call steadydata/hacker-news-comments --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,steadydata/hacker-news-comments"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/seKU4qzT1M0tgc2FV/builds/Xa78TcCUE1OWAwQYO/openapi.json
