# Hacker News Scraper - Search, Comments & Front Page (`conversational_kermis/hacker-news-scraper`) Actor

Search Hacker News stories and comments by keyword, author, points and date range with no 1000-result cap, pull the live top/new/best/Ask/Show/Jobs lists, or fetch items with their full comment trees. Clean plain-text fields. Official public APIs, no proxy.

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

## Pricing

from $0.16 / 1,000 item results

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 Scraper - Search, Front Page, Comments & Ask/Show HN

Scrape Hacker News three ways: search every story and comment ever posted (by keyword, type, author, points and date range), pull a live list such as the front page, or fetch specific items with their full comment threads. One clean row per item: title, link, domain, author, points, comment count, post time and plain-text body.

Uses only the official public APIs (Algolia HN Search and the Hacker News Firebase API). No browser, no proxy, so runs finish in seconds.

### Why this one

- **No 1000-result cap.** HN Search stops at 1000 hits per query. This Actor keeps going by walking back in time, so a search over two years returns every match, not the first 1000.
- **Full comment trees.** Turn on `includeComments` and each story row carries its whole thread, flattened into a list with `parentId` and `depth`, so you can rebuild the tree or just read it top to bottom. Still one row and one charge per story.
- **Live lists.** Top (front page), New, Best, Ask HN, Show HN and Jobs, in the site's own order, with live points and comment counts.
- **Clean fields.** Text is plain text: HTML stripped, entities decoded, links kept as full URLs. Times are ISO 8601 UTC. Comments carry the id and title of their story.

### What you can use it for

- Monitoring HN for mentions of your product, company or competitors
- Collecting launches (Show HN, Launch HN) in a niche over a date range
- Reading the monthly "Who is hiring?" thread as data
- Snapshotting the front page on a schedule
- Building datasets of stories or discussions for research and analysis

### Input

| Field | Type | Description |
|-------|------|-------------|
| `mode` | select | `search` (default), `list` or `items`. |
| `query` | string | Search keywords. Leave empty to match everything (with a type, author or date range). Matching is prefix-based: `llm` also matches `LLMs`. |
| `type` | select | `story` (default), `comment`, `ask_hn`, `show_hn`, `launch_hn`, `poll`, `job` or `all`. |
| `sortBy` | select | `relevance` (default: text match and popularity) or `date` (newest first). |
| `author` | string | Only items by this HN username. |
| `storyId` | string | Only items inside this story (id or item URL). With `type: comment`, searches one thread. |
| `minPoints` / `minComments` | integer | Only stories with at least this many points / comments. Ignored for comments. |
| `startDate` / `endDate` | string | Post date range, `YYYY-MM-DD`, UTC, both inclusive. |
| `listType` | select | For `mode: list`: `topstories`, `newstories`, `beststories`, `askstories`, `showstories`, `jobstories`. |
| `itemIds` | array | For `mode: items`: ids (`8863`) or URLs (`https://news.ycombinator.com/item?id=8863`). |
| `includeComments` | boolean | Add the full comment thread to each story row. Default `false`. |
| `maxItems` | integer | Maximum rows in total. Default `100`. `0` = no limit. |

#### Examples

Keyword monitoring, newest first (run it on a schedule):

```json
{
  "mode": "search",
  "query": "your-product",
  "type": "all",
  "sortBy": "date",
  "maxItems": 100
}
```

Every Show HN launch with 100+ points in October 2026, with comments:

```json
{
  "mode": "search",
  "type": "show_hn",
  "startDate": "2026-10-01",
  "endDate": "2026-10-31",
  "minPoints": 100,
  "includeComments": true,
  "maxItems": 500
}
```

A "Who is hiring?" thread as one row with all its comments:

```json
{
  "mode": "items",
  "itemIds": ["https://news.ycombinator.com/item?id=50338728"],
  "includeComments": true
}
```

Only the job posts in that thread that mention "remote", one row per comment:

```json
{
  "mode": "search",
  "type": "comment",
  "storyId": "50338728",
  "query": "remote",
  "sortBy": "date",
  "maxItems": 1000
}
```

The front page right now:

```json
{
  "mode": "list",
  "listType": "topstories",
  "maxItems": 30
}
```

### Output

One row per item. Example story row with `includeComments` (shortened, placeholder data):

```json
{
  "id": "40000001",
  "type": "story",
  "title": "Show HN: A tiny database written in a weekend",
  "url": "https://example.com/tiny-db",
  "hnUrl": "https://news.ycombinator.com/item?id=40000001",
  "domain": "example.com",
  "author": "example_user",
  "points": 245,
  "numComments": 87,
  "createdAt": "2026-10-14T16:02:11Z",
  "text": "I wanted to understand how B-trees work, so I wrote one.\n\nSource: https://github.com/example/tiny-db",
  "storyId": null,
  "storyTitle": null,
  "parentId": null,
  "tags": ["story", "show_hn", "front_page"],
  "comments": [
    {"id": "40000102", "author": "another_user", "text": "How does it handle crashes mid-write?", "createdAt": "2026-10-14T16:20:45Z", "parentId": "40000001", "depth": 0},
    {"id": "40000150", "author": "example_user", "text": "A write-ahead log, fsynced before each commit.", "createdAt": "2026-10-14T16:31:02Z", "parentId": "40000102", "depth": 1}
  ],
  "commentCount": 86,
  "scrapedAt": "2026-11-11T09:00:00Z"
}
```

| Field | Notes |
|-------|-------|
| `id`, `hnUrl` | Always present. `hnUrl` is the discussion page. |
| `type` | `story`, `comment`, `poll`, `pollopt` or `job`. Ask HN, Show HN and Launch HN are stories; see `tags`. |
| `title`, `url`, `domain` | Stories, polls and jobs. `url` is the external link, `null` for text posts such as Ask HN. |
| `author`, `points`, `numComments` | `points` and `numComments` are `null` for comments (HN does not publish comment scores). |
| `createdAt` | Post time, ISO 8601 UTC. |
| `text` | Body as plain text: Ask HN and Show HN text, comment text, job descriptions. |
| `storyId`, `storyTitle`, `parentId` | Comments only: the story the comment belongs to and the item it replies to. |
| `tags` | `story`, `comment`, `ask_hn`, `show_hn`, `launch_hn`, `front_page`, `poll`, `job`. `front_page` appears in search results only. |
| `comments`, `commentCount` | Only with `includeComments`. Depth-first: each reply follows its parent, siblings oldest first. `depth` 0 is a direct reply to the row's item. |
| `scrapedAt` | When the row was scraped. |

### Pricing

**$0.0002 per item** (one dataset row), so 1,000 rows cost $0.20. Comments embedded in a story row through `includeComments` are included in that row's price. With `type: comment` each comment is its own row and is charged as one item.

The run stops by itself when it reaches the maximum charge you set for it.

### FAQ

**How is this different from the HN search box?** HN Search (hn.algolia.com) shows at most 1000 results per query. This Actor uses the same index but keeps paging back in time, so you get every match in your date range. With `sortBy: relevance` the first 1000 rows are in relevance order and the rest follow newest first.

**Why is `commentCount` lower than `numComments`?** `numComments` is HN's own count. Flagged and dead comments are counted there but are not public, so they are not in the thread. Deleted comments are left out unless they have replies, in which case they stay with `author` and `text` set to `null` so the tree stays intact.

**Are comments in the order HN shows them?** No. Replies to the same parent are oldest first. HN's ranking order is not part of the public data.

**How fresh is the data?** Live lists and items read the official API, so points and comment counts are current. Search reads HN's Algolia index, which picks up new items within a few minutes; its points and comment counts can be a little behind.

**Can I get user profiles or karma?** Not in this version.

**Why did my run fail with "No Hacker News items matched"?** The search returned nothing. A failed run is not charged for rows it did not produce; loosen the filters and run again.

### Integration tips

- **Schedules:** run a `sortBy: date` search every hour or day to monitor keywords, or `mode: list` with `topstories` to snapshot the front page. Deduplicate on `id` across runs.
- **Webhooks:** add a webhook on "Run succeeded" to send new rows to Slack, a database or your own endpoint.
- **API:** start runs and read results with the Apify API or client libraries, for example `GET https://api.apify.com/v2/datasets/{datasetId}/items?format=json` (or `format=csv`). Nested `comments` come through as JSON arrays; for CSV, keep `includeComments` off or flatten on your side.

### Limits

- Search is limited to what HN's Algolia index holds: all public stories, comments, polls and jobs since 2006. Dead and flagged items are not included.
- `includeComments` costs one extra request per story, so big runs with comments take longer. The largest threads (several thousand comments) make rows of a few MB.
- Tested on searches over 2-year ranges (several thousand rows), the live lists, and threads with 1,600+ comments.

# Actor input Schema

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

Search: keyword/author/date search over all of Hacker News (fill in the Search section). Live list: the current Top, New, Best, Ask, Show or Jobs list. Specific items: the stories or comments whose ids or URLs you paste.

## `query` (type: `string`):

Keywords, as you would type them into hn.algolia.com. Leave empty to match everything (useful with Type, Author or a date range). Matching is prefix-based, so "llm" also matches "LLMs".

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

Which kind of item to return. Ask HN, Show HN and Launch HN are stories. With Comments, every comment is its own row.

## `sortBy` (type: `string`):

Relevance ranks by text match and popularity (points, comments). Date returns newest first. Past the first 1000 results a relevance search continues newest first.

## `author` (type: `string`):

Optional. Only items posted by this HN username (case-sensitive, as shown on the site).

## `storyId` (type: `string`):

Optional. Only items belonging to this story: an id or a news.ycombinator.com/item?id= URL. With Type = Comments and a query, this searches inside one thread (for example "remote" inside a Who is hiring thread).

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

Optional. Only stories with at least this many points. Ignored for comments (HN does not expose comment points).

## `minComments` (type: `integer`):

Optional. Only stories with at least this many comments. Ignored for comments.

## `startDate` (type: `string`):

Optional. Earliest post date (YYYY-MM-DD, UTC), inclusive.

## `endDate` (type: `string`):

Optional. Latest post date (YYYY-MM-DD, UTC), inclusive.

## `listType` (type: `string`):

Used when What to scrape = Live list. Items come in the list's own order (front-page rank for Top) with live points and comment counts. Top, New and Best hold up to 500 stories; Ask, Show and Jobs up to 200.

## `itemIds` (type: `array`):

Used when What to scrape = Specific items. HN item ids ("8863") or URLs ("https://news.ycombinator.com/item?id=8863"), one per line. Stories, comments, polls and jobs all work.

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

Add the full comment tree to each story row as a flat `comments` list (author, plain text, time, parentId, depth) plus `commentCount`. Still one row (one charge) per story. One extra request per story, so large runs take longer.

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

Maximum rows to return in total. Searches go past Algolia's 1000-result cap automatically by walking back in time. 0 = no limit (a broad search can return millions of rows, so set a budget).

## Actor input object example

```json
{
  "mode": "search",
  "query": "llm",
  "type": "story",
  "sortBy": "relevance",
  "listType": "topstories",
  "includeComments": false,
  "maxItems": 25
}
```

# 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 = {
    "mode": "search",
    "query": "llm",
    "maxItems": 25
};

// Run the Actor and wait for it to finish
const run = await client.actor("conversational_kermis/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 = {
    "mode": "search",
    "query": "llm",
    "maxItems": 25,
}

# Run the Actor and wait for it to finish
run = client.actor("conversational_kermis/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 '{
  "mode": "search",
  "query": "llm",
  "maxItems": 25
}' |
apify call conversational_kermis/hacker-news-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,conversational_kermis/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/6acyd3iEb4Sbqrfwp/builds/I627XAiMCO2ihjaNN/openapi.json
