# Hacker News Scraper: Stories, Scores and Comments (`capable_coach/hacker-news-scraper`) Actor

Hacker News as clean JSON: ranked stories from the top, new, best, ask, show and job feeds with score, author, domain and comment count, plus optional top-level comments. Filter by score or age; only-new mode for scheduled runs. $0.40 per 1,000 items.

- **URL**: https://apify.com/capable_coach/hacker-news-scraper.md
- **Developed by:** [jules imbert](https://apify.com/capable_coach) (community)
- **Categories:** News, Social media, 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.40 / 1,000 story or comments

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

Turn the official Hacker News API into a ranked JSON dataset: one row per story, optionally per top-level comment, ready for SQL, a spreadsheet or a monitoring pipeline.

### What you get

- Stories from the `top`, `new`, `best`, `ask`, `show` and `job` feeds with their rank at scrape time.
- Title, target URL, domain, author, score, comment count, creation time and the Hacker News permalink.
- Self-post text with HTML stripped, flags for dead and deleted items.
- Optional top-level comment rows (up to 50 per story) tagged `recordType: "comment"`.
- An only-new mode that remembers delivered story IDs, so a scheduled run emits only what appeared since.

Real output shape (trimmed):

```json
{
  "recordType": "story",
  "feed": "top",
  "rank": 1,
  "id": 50606192,
  "title": "Free alternative TV network built from the Internet Archive's forgotten videos",
  "url": "https://spelunkr.tv",
  "domain": "spelunkr.tv",
  "hnUrl": "https://news.ycombinator.com/item?id=50606192",
  "author": "SockThief",
  "score": 382,
  "commentsCount": 55,
  "createdAt": "2026-11-23T01:13:51.000Z"
}
```

### Who it's for

- **Trend analysts** who need rank and score history, not a front-page screenshot.
- **Newsletter writers** mining headlines, dominant domains and comment activity.
- **Founders and investors** watching which products reach the front page.
- **Data engineers** feeding a warehouse or dashboard on a cron.

### How to use

1. Choose `feeds` (default `top`) and `maxItems` per feed (up to 1,000).
2. Optionally set `minScore`, `sinceHours` and `maxCommentsPerStory` to add top-level comment rows.
3. Run it and export JSON, CSV or Excel. For a digest, turn on `onlyNewSinceLastRun` with a distinct `stateKey` per schedule.

Example input:

```json
{
  "feeds": ["top"],
  "maxItems": 20,
  "minScore": 100,
  "maxCommentsPerStory": 3
}
```

### Pricing

Pay per event, no subscription: **$0.0005 per run start** (one event per GB of memory, minimum one) plus **$0.0004 per story or comment** written to the dataset.

| Volume (Free plan) | Cost |
|---|---|
| 100 items | $0.0405 |
| 1,000 items | $0.4005 |

`maxItems` caps stories per feed, not total rows: combining feeds and comments multiplies the number of billed items.

Set the run's *Maximum cost per run* in Apify to cap spending in advance.

### FAQ

**Is an API key needed?**
No. The actor reads the public Hacker News API, the same source as news.ycombinator.com.

**Does it need a proxy?**
No: it uses an API, not HTML scraping.

**Can I get comments?**
Yes, top-level comments only (up to 50 per story) with `maxCommentsPerStory`. Deeper replies are not fetched.

**How do I track what climbs the front page?**
Run it hourly on `top` and compare `rank` per `id` between runs; store `scrapedAt` to order the snapshots.

**How do I avoid duplicates on a schedule?**
Set `onlyNewSinceLastRun: true`, with a distinct `stateKey` for each schedule; nothing new is a success with zero rows.

**Can I search by keyword or user?**
No. The actor reads the six feeds; there is no keyword search or user-profile endpoint.

### Limits

- Comments are top-level only; no full threads.
- `rank` is a snapshot at run time.
- Deleted and dead items are skipped, so `commentsCount` can exceed the comment rows you receive.
- `feeds` accepts only `top`, `new`, `best`, `ask`, `show` and `job`.
- If no story is collected the run fails instead of returning an empty dataset.
- Not affiliated with Y Combinator or Hacker News.

# Changelog

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

# Actor input Schema

## `feeds` (type: `array`):

Un ou plusieurs flux, valeurs acceptées : top, new, best, ask, show, job.

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

Plafond de stories collectées par flux (le classement HN est conservé).

## `minScore` (type: `integer`):

Ne garder que les stories avec au moins ce nombre de points.

## `sinceHours` (type: `integer`):

0 = pas de filtre d'âge.

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

Récupère les commentaires de premier niveau de chaque story (lignes recordType=comment).

## `onlyNewSinceLastRun` (type: `boolean`):

Mémorise les stories déjà livrées (key-value store) et ne renvoie que les nouvelles. À utiliser en tâche planifiée ; un run sans nouveauté sort en succès avec 0 ligne.

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

Deux tâches planifiées différentes doivent utiliser deux stateKey distincts, sinon elles partagent la mémoire des stories déjà livrées.

## Actor input object example

```json
{
  "feeds": [
    "top"
  ],
  "maxItems": 100,
  "minScore": 0,
  "sinceHours": 0,
  "maxCommentsPerStory": 0,
  "onlyNewSinceLastRun": false,
  "stateKey": "default"
}
```

# Actor output Schema

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

One row per review written to the default dataset.

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

Pre-formatted table view of the reviews.

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

Counts per app: reviews read, written, errors.

# 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 = {
    "feeds": [
        "top"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("capable_coach/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 = { "feeds": ["top"] }

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

```

## MCP server setup

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