# Hacker News Top Stories (`reverberant_equality/hn-top-stories`) Actor

Scrape top stories from Hacker News by section. Extract story titles, URLs, points, authors, and comment counts from the front page, new, ask, show, or jobs sections.

- **URL**: https://apify.com/reverberant\_equality/hn-top-stories.md
- **Developed by:** [Jordan C](https://apify.com/reverberant_equality) (community)
- **Categories:** AI
- **Stats:** 2 total users, 0 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.01 / 1,000 results

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

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

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Hacker News Top Stories Scraper

A [Cheerio](https://cheerio.js.org/)-based [Apify Actor](https://apify.com/actors) that scrapes top stories from [Hacker News](https://news.ycombinator.com/) with pagination support.

### Features

- Scrapes stories by section: **Top**, **New**, **Ask HN**, **Show HN**, **Jobs**
- Extracts: rank, title, URL, domain, points, author, comment count, comment URL, posted age, scraped timestamp
- Paginates through the "More" link to reach the requested number of results
- Configurable max results (1–500, default 30)

### Input

| Field        | Type    | Default | Description                                      |
|-------------|---------|---------|--------------------------------------------------|
| `section`   | enum    | `top`   | HN section: `top`, `new`, `ask`, `show`, `jobs` |
| `maxResults`| integer | `30`    | Maximum number of stories to collect (1–500)     |

### Output Fields

| Field        | Type    | Description                                  |
|-------------|---------|----------------------------------------------|
| `rank`      | integer | Position on the page (1-indexed)             |
| `title`     | string  | Story title                                  |
| `url`       | string  | Link to the story                            |
| `domain`    | string  | Domain extracted from the URL                |
| `points`    | integer | Upvote score                                 |
| `author`    | string  | Submission author username                   |
| `comments`  | integer | Number of comments (0 if none)               |
| `commentUrl`| string  | Link to the HN discussion page               |
| `postedAge` | string  | Relative time string (e.g., "2 hours ago")   |
| `scrapedAt` | string  | ISO 8601 timestamp when scraped              |

### Usage

```bash
## Install dependencies
npm install

## Run locally (uses .actor/input_schema.json defaults or storage/key_value_stores/default/INPUT.json)
apify run

## Build for production
npm run build

## Validate input schema
apify validate-schema
```

### Local Development

1. Set input in `storage/key_value_stores/default/INPUT.json` or use `apify run --input`:
   ```json
   { "section": "show", "maxResults": 10 }
   ```
2. Run: `npm run start:dev` or `apify run`

### Deployment

```bash
apify login
apify push
```

### Technical Notes

- Built with **Crawlee CheerioCrawler** — no browser overhead, fast scraping
- Automatically paginates through HN's "More" links
- Handles Ask HN / Show HN relative URLs
- Uses Apify proxy configuration for reliable access
- PPE charge events: `search-start` ($0.005) and `story-result` ($0.002 per story)

# Actor input Schema

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

Which Hacker News section to scrape.

## `maxResults` (type: `integer`):

Maximum number of stories to return.

## Actor input object example

```json
{
  "section": "top",
  "maxResults": 30
}
```

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

// Run the Actor and wait for it to finish
const run = await client.actor("reverberant_equality/hn-top-stories").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("reverberant_equality/hn-top-stories").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).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 reverberant_equality/hn-top-stories --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=reverberant_equality/hn-top-stories",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/acts/PSFcTqMYa0LKq1wc1/builds/kT1h4dco1DkfYQo2N/openapi.json
