# Hacker News Scraper (`cloud9_ai/hackernews-scraper`) Actor

Scrape Hacker News stories, comments, and user profiles via official Firebase API. Get top, new, best, ask, show stories with scores, comments, and author data.

- **URL**: https://apify.com/cloud9\_ai/hackernews-scraper.md
- **Developed by:** [cloud9](https://apify.com/cloud9_ai) (community)
- **Categories:** AI, Marketing
- **Stats:** 4 total users, 2 monthly users, 100.0% runs succeeded, 1 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.00 / 1,000 results

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/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
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.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use 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 Story Scraper

Extract tech stories, jobs, and discussions from Hacker News using the official Firebase API. Get top/best/new stories, Ask HN, Show HN, and job postings with full metadata.

### Features

- **Official API-based** - Zero blocking, 100% reliability (uses `hacker-news.firebaseio.com`)
- **6 story types** - Top, Best, New, Ask HN, Show HN, Jobs
- **Score filtering** - Filter by minimum upvotes
- **Keyword search** - Search in titles (case-insensitive)
- **Full metadata** - Title, URL, score, author, comments, timestamp, HN link

### Use Cases

- **Tech trend monitoring** - Track trending technologies and discussions
- **Startup/product research** - Discover new products and startup launches
- **Competitive intelligence** - Monitor competitor mentions and discussions
- **Content curation** - Find quality content for newsletters/social media
- **Recruitment** - Browse job postings from tech companies
- **Market research** - Analyze what the tech community is interested in

### Input Parameters

| Field | Type | Required | Default | Description |
|-------|------|----------|---------|-------------|
| `storyType` | string | Yes | `"top"` | Type of stories: `top`, `best`, `new`, `ask`, `show`, `job` |
| `maxResults` | number | No | `50` | Maximum stories to extract (1-500) |
| `minScore` | number | No | - | Only include stories with this many upvotes or more |
| `keyword` | string | No | - | Only include stories with this keyword in title |

#### Story Types

- **Top Stories** - Currently trending stories
- **Best Stories** - Best stories based on HN algorithm
- **New Stories** - Most recently submitted stories
- **Ask HN** - Questions and discussions
- **Show HN** - Project/product showcases
- **Jobs** - Job postings

### Output Format

Each story includes:

```json
{
  "id": 39631123,
  "title": "Show HN: I built a tool to analyze Hacker News trends",
  "url": "https://example.com/hn-analyzer",
  "score": 342,
  "author": "techfounder",
  "commentCount": 87,
  "postedAt": "2024-02-12T10:30:00.000Z",
  "type": "story",
  "hnUrl": "https://news.ycombinator.com/item?id=39631123",
  "scrapedAt": "2024-02-12T15:45:00.000Z"
}
````

#### Field Descriptions

- **id** - Unique HN story ID
- **title** - Story title
- **url** - External URL (null for Ask HN/text posts)
- **score** - Number of upvotes
- **author** - HN username of submitter
- **commentCount** - Number of comments/discussions
- **postedAt** - Submission timestamp (ISO 8601)
- **type** - Story type (story, job, poll, etc.)
- **hnUrl** - Direct link to HN discussion page
- **scrapedAt** - Timestamp when data was extracted

### Example Usage

#### Top 30 AI-related stories with minimum 50 upvotes

```json
{
  "storyType": "top",
  "maxResults": 30,
  "minScore": 50,
  "keyword": "AI"
}
```

#### Recent Show HN projects

```json
{
  "storyType": "show",
  "maxResults": 100,
  "minScore": 10
}
```

#### Job postings from YC companies

```json
{
  "storyType": "job",
  "maxResults": 50,
  "keyword": "YC"
}
```

#### Best Ask HN questions

```json
{
  "storyType": "ask",
  "maxResults": 25,
  "minScore": 100
}
```

### Pricing

Approximately **$2.50 per 1,000 stories** (based on compute units)

#### Cost Estimation

| Stories | Approx. Cost | Duration |
|---------|--------------|----------|
| 50 | $0.12 | ~30 seconds |
| 100 | $0.25 | ~1 minute |
| 500 | $1.25 | ~5 minutes |

*Costs include API calls and rate limiting (0.5s between requests)*

### Tips & Best Practices

#### Filtering Strategy

If you need 50 stories with specific filters (minScore/keyword):

- Set `maxResults` higher (100-150) to account for filtered items
- The actor fetches up to 2x maxResults to ensure enough matches

#### Story Type Selection

- **Top** - Most balanced view of current trending content
- **Best** - Highest quality stories (better signal-to-noise)
- **New** - Real-time monitoring, catch stories early
- **Ask** - Community discussions, Q\&A, career advice
- **Show** - New product launches, side projects
- **Job** - Tech job opportunities, mostly from startups

#### Rate Limiting

- Actor respects HN API with 0.5s delay between requests
- 50 stories = ~30 seconds
- 500 stories = ~5 minutes
- No risk of being blocked (official API)

#### Data Freshness

- Stories are fetched in real-time from HN API
- Top/Best/New lists update frequently (every few minutes)
- Job postings update less frequently

#### Keyword Matching

- Case-insensitive search
- Matches anywhere in title
- Examples: "AI", "LLM", "YC", "startup", "open source"
- For multiple keywords, run separate actors and merge results

### Technical Details

#### API Endpoints Used

- Story IDs: `https://hacker-news.firebaseio.com/v0/{type}stories.json`
- Story details: `https://hacker-news.firebaseio.com/v0/item/{id}.json`

#### Rate Limiting

- 0.5 second delay between story detail requests
- Public API, no authentication required
- No IP blocking or rate limits

#### Error Handling

- Continues on individual story fetch failures
- Logs warnings for failed requests
- Returns all successfully fetched stories

#### Data Quality

- All data comes directly from HN official API
- No web scraping, no parsing errors
- 100% reliability and accuracy

### Common Use Cases

#### 1. Startup Trend Analysis

Track what startups are launching and getting traction:

```json
{
  "storyType": "show",
  "maxResults": 200,
  "minScore": 20
}
```

#### 2. AI/ML News Monitoring

Stay updated on AI developments:

```json
{
  "storyType": "best",
  "maxResults": 100,
  "keyword": "AI"
}
```

#### 3. Job Board Scraping

Build a job aggregator:

```json
{
  "storyType": "job",
  "maxResults": 500
}
```

#### 4. Content Curation

Find high-quality content for newsletters:

```json
{
  "storyType": "best",
  "maxResults": 50,
  "minScore": 100
}
```

### Limitations

- Maximum 500 stories per run (API limitation)
- Keyword search is simple substring match (not full-text search)
- Rate limited to ~120 stories/minute (to respect HN API)
- No access to comment content (only comment counts)

### Support

For issues or feature requests, please contact the actor maintainer.

### License

This actor is provided as-is for use on the Apify platform.

# Actor input Schema

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

Type of stories to scrape

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

Maximum number of stories to extract (1-500)

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

Only include stories with this many upvotes or more

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

Only include stories with this keyword in the title (case-insensitive)

## Actor input object example

```json
{
  "storyType": "top",
  "maxResults": 50
}
```

# 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("cloud9_ai/hackernews-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("cloud9_ai/hackernews-scraper").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 cloud9_ai/hackernews-scraper --silent --output-dataset

```

## MCP server setup

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

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Hacker News Scraper",
        "description": "Scrape Hacker News stories, comments, and user profiles via official Firebase API. Get top, new, best, ask, show stories with scores, comments, and author data.",
        "version": "0.1",
        "x-build-id": "lpl8LHnWqEGa8oU6A"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/cloud9_ai~hackernews-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-cloud9_ai-hackernews-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/cloud9_ai~hackernews-scraper/runs": {
            "post": {
                "operationId": "runs-sync-cloud9_ai-hackernews-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/cloud9_ai~hackernews-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-cloud9_ai-hackernews-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "storyType"
                ],
                "properties": {
                    "storyType": {
                        "title": "Story Type",
                        "enum": [
                            "top",
                            "best",
                            "new",
                            "ask",
                            "show",
                            "job"
                        ],
                        "type": "string",
                        "description": "Type of stories to scrape",
                        "default": "top"
                    },
                    "maxResults": {
                        "title": "Maximum Results",
                        "minimum": 1,
                        "maximum": 500,
                        "type": "integer",
                        "description": "Maximum number of stories to extract (1-500)",
                        "default": 50
                    },
                    "minScore": {
                        "title": "Minimum Score",
                        "minimum": 0,
                        "type": "integer",
                        "description": "Only include stories with this many upvotes or more"
                    },
                    "keyword": {
                        "title": "Keyword Filter",
                        "type": "string",
                        "description": "Only include stories with this keyword in the title (case-insensitive)"
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
