# Hacker News Scraper — Stories, Search & Comments API (`reverend_sal/hacker-news-scraper`) Actor

Scrape Hacker News front page, new, best, Ask HN and Show HN stories, search all of HN by keyword, points and date, and export full comment threads. Uses the official HN and Algolia APIs: fast, no blocking. Pay per result.

- **URL**: https://apify.com/reverend_sal/hacker-news-scraper.md
- **Developed by:** [North Eng](https://apify.com/reverend_sal) (community)
- **Categories:** News, Developer tools
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.20 / 1,000 stories

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

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 Scraper — Stories, Search & Comments API

**Hacker News Scraper** exports stories from Hacker News: the front page, newest, best, Ask HN and Show HN lists, keyword search across all of HN since 2006, or specific stories by link. Each story has title, URL, domain, points, comment count, author, date and text, and you can add the full comment thread with authors, replies and depth.

It uses the two official Hacker News APIs, the HN Firebase API and the HN Search API by Algolia. No HTML scraping, no blocking, no proxies: the front page takes about a second.

### What it does

- **Story lists**: `top` (front page, with rank), `new`, `best`, `ask` (Ask HN) and `show` (Show HN), up to 500 stories each.
- **Search all of Hacker News**: keywords in titles, URLs and text; restrict to Ask HN, Show HN, polls or the current front page; sort by relevance or date; up to 1,000 results per query.
- **Specific stories**: paste HN item links or IDs.
- **Comment threads**: optional, in HN's ranking order for top-level comments, with replies nested depth-first (`depth`, `parentId`). Limit by count or depth.
- **Filters**: minimum points and "posted since" date in every mode.
- **Clean text**: Ask HN posts and comments come as readable plain text (paragraphs kept, links expanded to full URLs, HTML entities decoded).

### Why use it

- **Trend and launch tracking**: monitor what's on the front page, or every mention of your product, competitors or tech stack.
- **Market and developer research**: collect Show HN launches or Ask HN discussions on a topic.
- **AI and NLP datasets**: export comment threads for summarisation, sentiment analysis or RAG.
- **Newsletters and dashboards**: schedule daily runs of the best stories above 200 points.

### How to use

1. Choose **What to scrape**: a story list, a search, or specific stories.
2. Set the list, the search query, or paste story links.
3. Optional: set **Minimum points**, **Posted since**, **Max stories**, and turn on **Include comments**.
4. Click **Start** and export the dataset as JSON, CSV or Excel, or fetch it with the Apify API.

### Input

| Field | Default | What it does |
|---|---|---|
| `mode` | `list` | `list`, `search` or `stories`. |
| `list` | `top` | `top`, `new`, `best`, `ask` or `show` (list mode). |
| `searchQuery` | empty | Keywords (search mode). Empty = all stories matching the filters. |
| `searchType` | `story` | `story`, `ask_hn`, `show_hn`, `front_page` or `poll`. |
| `searchSort` | `relevance` | `relevance` or `date` (newest first). |
| `storyIds` | none | HN item IDs or links (stories mode). |
| `minPoints` | 0 | Only stories with at least this many points. |
| `sinceDate` | none | Only stories posted on or after this date (`YYYY-MM-DD`). |
| `maxItems` | 30 | Maximum stories (lists up to 500, search up to 1,000). |
| `includeComments` | `false` | Add the comment thread to each story. |
| `maxCommentsPerStory` | 200 | Comment cap per story (up to 5,000). |
| `maxCommentDepth` | 0 | 1 = top-level comments only, 2 = plus replies, … 0 = unlimited. |
| `maxConcurrency` | 5 | Parallel API requests. |

Examples:

```json
{ "mode": "search", "searchQuery": "rust", "minPoints": 500, "maxItems": 150 }
```

```json
{ "mode": "search", "searchType": "show_hn", "searchSort": "date", "sinceDate": "2026-10-01", "maxItems": 200 }
```

```json
{ "mode": "stories", "storyIds": ["https://news.ycombinator.com/item?id=8863"], "includeComments": true, "maxCommentDepth": 3 }
```

### Output

Real example from the default input (front page, Oct 22 2026):

```json
{
  "id": 50195959,
  "title": "Quad9 (DNS Resolver) to Exit France",
  "url": "https://quad9.net/news/blog/au-revoir-france/",
  "domain": "quad9.net",
  "hnUrl": "https://news.ycombinator.com/item?id=50195959",
  "type": "story",
  "author": "farrokhi",
  "points": 960,
  "commentsCount": 346,
  "createdAt": "2026-10-22T14:32:38.000Z",
  "text": null,
  "rank": 1,
  "scrapedAt": "2026-10-23T00:15:36.686Z"
}
```

`type` is `story`, `ask`, `show` or `poll`. `rank` is the position in the list (list mode only). `text` holds the body of Ask HN and text posts.

With **Include comments** on, each story also has `comments` and `commentsIncluded` (real example, texts shortened):

```json
{
  "id": 8863,
  "title": "My YC app: Dropbox - Throw away your USB drive",
  "points": 104,
  "commentsCount": 71,
  "comments": [
    { "id": 9224, "parentId": 8863, "depth": 0, "author": "BrandonM", "text": "I have a few qualms with this app:\n\n1. For a Linux user, …", "createdAt": "2007-04-05T15:16:54.000Z" },
    { "id": 9272, "parentId": 9224, "depth": 1, "author": "dhouston", "text": "1. re: the first part, many people want something plug and play. …", "createdAt": "2007-04-05T16:47:01.000Z" }
  ],
  "commentsIncluded": 64
}
```

`commentsCount` is HN's total; `commentsIncluded` can be lower because of your limits and because deleted comments (and their replies) are skipped.

Requested stories that can't be saved are listed with an error and are **not charged**: `NOT_FOUND`, `NOT_A_STORY` (a comment or a job ad), `TIMEOUT`, `NETWORK_ERROR`.

### Pricing

Pay per result:

| Event | Price |
|---|---|
| Story saved | **$0.0002** ($0.20 per 1,000) |
| Comment included (only with "Include comments") | **$0.0001** ($0.10 per 1,000) |
| Actor start | Apify default ($0.00005) |

Examples: the front page (30 stories) costs **$0.006**; 1,000 search results **$0.20**; the 10 best stories with all their comments (about 4,400) about **$0.44**. Set a max cost per run and the Actor stops when the budget is reached; the last story's comments are trimmed to fit (`commentsTruncatedByBudget: true`).

### FAQ

**Is this allowed?**
Yes. It uses the public Hacker News API (published by Y Combinator) and the HN Search API by Algolia, both meant for programmatic access. It does not scrape HTML or log in.

**Why are job posts missing?**
YC job ads (`type: job`) are skipped in lists and rejected in stories mode. This Actor is for stories and discussions.

**Can I get more than 1,000 search results?**
Algolia returns at most 1,000 hits per query. Split the query by date with **Posted since** and several runs.

**How fresh is the data?**
Lists and items come live from the HN API. Search results are usually indexed within minutes.

### Limitations

- Search covers stories (not comment search) and is capped at 1,000 results per query.
- Replies are ordered chronologically under their parent; only top-level comments follow HN's ranking.
- User profiles and karma are not included.

# Actor input Schema

## `mode` (type: `string`):

A Hacker News list (front page, new, best, Ask HN, Show HN), a keyword search across all of HN, or specific stories by ID/URL.

## `list` (type: `string`):

Used when "What to scrape" is a story list.

## `searchQuery` (type: `string`):

Keywords to search story titles, URLs and text, e.g. "rust" or "apify". Used in Search mode; leave empty to list all stories matching the filters.

## `searchType` (type: `string`):

Which posts to search.

## `searchSort` (type: `string`):

Relevance (best matches, weighted by points) or date (newest first).

## `storyIds` (type: `array`):

Used in "Specific stories" mode: HN item IDs (8863) or links like https://news.ycombinator.com/item?id=8863.

## `minPoints` (type: `integer`):

Only keep stories with at least this many points.

## `sinceDate` (type: `string`):

Only keep stories posted on or after this date (YYYY-MM-DD).

## `maxItems` (type: `integer`):

Maximum stories to save (lists have up to 500, search up to 1,000).

## `includeComments` (type: `boolean`):

Add each story's comment thread (author, text, date, depth, parent) to the story. Charged per comment.

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

Cap on comments saved per story (top-level comments in HN ranking order, replies follow their parent).

## `maxCommentDepth` (type: `integer`):

1 = top-level comments only, 2 = plus direct replies, … 0 = unlimited.

## `maxConcurrency` (type: `integer`):

Parallel API requests.

## Actor input object example

```json
{
  "mode": "list",
  "list": "top",
  "searchQuery": "",
  "searchType": "story",
  "searchSort": "relevance",
  "storyIds": [],
  "minPoints": 0,
  "sinceDate": "",
  "maxItems": 30,
  "includeComments": false,
  "maxCommentsPerStory": 200,
  "maxCommentDepth": 0,
  "maxConcurrency": 5
}
```

# Actor output Schema

## `stories` (type: `string`):

One row per story with title, URL, points, comment count, author, date and (optionally) comments.

## `summary` (type: `string`):

Stories and comments saved, failures and items skipped by filters.

# 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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("reverend_sal/hacker-news-scraper").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 = {}

# Run the Actor and wait for it to finish
run = client.actor("reverend_sal/hacker-news-scraper").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 '{}' |
apify call reverend_sal/hacker-news-scraper --silent --output-dataset

```

## MCP server setup

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

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/b11pldG9W5nE3ch62/builds/8jY2LtGHkJsKrpop7/openapi.json
