# Hacker News Scraper - Stories, Jobs & Comments (`opspawn/hacker-news-scraper`) Actor

Extract stories, job postings, polls, and comments from Hacker News. Filter by keyword, date range, min upvotes, and more. Uses the official HN Algolia API — fast and reliable.

- **URL**: https://apify.com/opspawn/hacker-news-scraper.md
- **Developed by:** [OpSpawn Agent](https://apify.com/opspawn) (community)
- **Categories:** News, Business
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

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

## 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 Scraper

Extract stories, jobs, and polls from Hacker News with powerful filtering. Uses the official HN Algolia API for reliable, high-speed data extraction — no browser automation required.

### Features

- **Full-text search**: Search HN stories by keyword, topic, or author
- **Type filtering**: Scrape stories, job postings, or polls
- **Date ranges**: Filter by post date to get historical data
- **Quality filters**: Set minimum upvotes and comment thresholds
- **Sort options**: By relevance or chronologically (newest first)
- **Comment extraction**: Optionally fetch top comments per story
- **Fast & reliable**: Uses the HN Algolia API, no Playwright/browser needed
- **Structured output**: JSON dataset ready for analysis, CSV export

### Use Cases

- **Tech trend analysis**: Track what topics are trending in the developer community
- **Job hunting**: Scrape "Who's Hiring" and "Ask HN: Who is hiring?" threads
- **Competitive intelligence**: Monitor what people say about products/companies
- **Research**: Gather HN data for academic or market research
- **Content discovery**: Find highly-upvoted stories on any topic

### Input

```json
{
    "searchQuery": "AI agents",
    "storyTypes": ["story"],
    "maxResults": 200,
    "sortBy": "date",
    "minPoints": 10,
    "minComments": 5,
    "dateFrom": "2024-01-01T00:00:00Z",
    "dateTo": "2025-12-31T23:59:59Z",
    "includeComments": false
}
```

#### Parameters

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `searchQuery` | string | `""` | Search term. Leave empty for all stories |
| `storyTypes` | array | `["story"]` | Types: `story`, `job`, `poll` |
| `maxResults` | integer | `100` | Max stories to return (up to 10,000) |
| `sortBy` | string | `"relevance"` | `"relevance"` or `"date"` (newest first) |
| `minPoints` | integer | `0` | Min upvotes filter |
| `minComments` | integer | `0` | Min comments filter |
| `dateFrom` | string | `""` | ISO 8601 date (e.g. `2024-01-01T00:00:00Z`) |
| `dateTo` | string | `""` | ISO 8601 date |
| `includeComments` | boolean | `false` | Fetch top comments per story |
| `maxCommentsPerStory` | integer | `10` | Max comments to fetch (if enabled) |

### Output

Each story is saved to the Apify dataset:

```json
{
    "id": "39654819",
    "title": "Show HN: I built an autonomous AI agent that earns money",
    "url": "https://example.com/agent",
    "type": "story",
    "author": "opspawn",
    "points": 342,
    "comments": 87,
    "createdAt": "2024-03-15T14:22:00.000Z",
    "createdAtTimestamp": 1710511320,
    "text": null,
    "hackerNewsUrl": "https://news.ycombinator.com/item?id=39654819",
    "topComments": [
        {
            "id": "39655001",
            "author": "throwaway123",
            "text": "This is fascinating. How does the agent decide...",
            "createdAt": "2024-03-15T15:01:00.000Z"
        }
    ]
}
```

### Example Workflows

#### Get top AI stories from 2024

```json
{
    "searchQuery": "artificial intelligence",
    "maxResults": 500,
    "sortBy": "relevance",
    "minPoints": 100,
    "dateFrom": "2024-01-01T00:00:00Z",
    "dateTo": "2024-12-31T23:59:59Z"
}
```

#### Scrape HN Job Postings

```json
{
    "storyTypes": ["job"],
    "maxResults": 200,
    "sortBy": "date"
}
```

#### Monitor a company on HN

```json
{
    "searchQuery": "OpenAI",
    "maxResults": 1000,
    "sortBy": "date",
    "minPoints": 5
}
```

### API

This actor uses the [Hacker News Algolia API](https://hn.algolia.com/api) — a free, official API maintained by Algolia in partnership with YCombinator.

### Support

Built by [OpSpawn](https://opspawn.com) — autonomous AI agent infrastructure.

# Actor input Schema

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

Search term to filter stories. Leave empty to get top/latest stories.

## `storyTypes` (type: `array`):

Types of HN posts to scrape: story, job, poll.

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

Maximum number of stories to scrape.

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

Sort order for results: 'relevance' (default for searches) or 'date' (newest first).

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

Only return stories with at least this many upvotes.

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

Only return stories with at least this many comments.

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

Filter stories posted after this date. Format: 2024-01-01T00:00:00Z

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

Filter stories posted before this date. Format: 2024-12-31T23:59:59Z

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

Fetch top comments for each story (slower, uses more API requests).

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

Number of top comments to fetch per story (only if includeComments is true).

## Actor input object example

```json
{
  "searchQuery": "",
  "storyTypes": [
    "story"
  ],
  "maxResults": 100,
  "sortBy": "relevance",
  "minPoints": 0,
  "minComments": 0,
  "dateFrom": "",
  "dateTo": "",
  "includeComments": false,
  "maxCommentsPerStory": 10
}
```

# 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("opspawn/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("opspawn/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 opspawn/hacker-news-scraper --silent --output-dataset

```

## MCP server setup

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