# Hacker News Stories & Comments Scraper (`mellora/hacker-news-stories-comments-scraper`) Actor

Extracts Hacker News stories, comments and search results by keyword, date range or author into structured JSON using HN's public Algolia API.

- **URL**: https://apify.com/mellora/hacker-news-stories-comments-scraper.md
- **Developed by:** [James Barnes](https://apify.com/mellora) (community)
- **Categories:** News
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$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/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 Stories & Comments Scraper

Track what Hacker News says about your product, competitors or topic. Search stories and comments by keyword, date range, author or story ID and get clean structured JSON, ready for monitoring, research or sentiment analysis.

### Sample output

```json
{
  "id": "8863",
  "type": "story",
  "title": "My YC app: Dropbox - Throw away your USB drive",
  "url": "http://www.getdropbox.com/u/2/screencast.html",
  "text": null,
  "author": "dhouston",
  "points": 104,
  "numComments": 71,
  "createdAt": "2007-04-04T19:16:40Z",
  "storyId": null,
  "storyTitle": null,
  "parentId": null,
  "hnUrl": "https://news.ycombinator.com/item?id=8863"
}
```

### What it does

Uses Hacker News's public Algolia search API (no login, no key). Only publicly visible data is read.

- Search stories, comments, polls, Show HN and Ask HN
- Filter by date range, author, minimum points, or a specific story (get an entire comment thread)
- Sort by relevance or newest first
- Grab the current front page

### Input

- **query**: keywords
- **contentType**: story, comment, poll, show_hn, ask_hn, front_page
- **sortBy**: relevance or date
- **author**, **storyId**: filters
- **dateFrom / dateTo**: YYYY-MM-DD (UTC)
- **minPoints**: stories only
- **maxItems**: up to 1000

At least one of query, author, storyId, a date, or the front_page type is required.

### Output fields

id, type, title, url, text, author, points, numComments, createdAt, storyId, storyTitle, parentId, hnUrl.

Author is the public HN username; no emails or phone numbers are collected.

### Pricing

$0.002 per result (charged per dataset item, so $2 per 1,000 results).

### Limits

- The Algolia API returns at most 1,000 results per query. To go deeper, split your search into date ranges.
- Comment search returns comments with their story context; to fetch a full thread use contentType `comment` with `storyId`.
- Requests are rate-limited politely and retried with backoff on 429 errors.

# Actor input Schema

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

Keywords to search for in titles, text and URLs. Leave empty to filter only by author, date or story.

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

What to return: stories, comments, polls, Show HN, Ask HN, or current front page.

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

Relevance or most recent first.

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

Only return items posted by this Hacker News user (public username).

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

Only return items belonging to this story (useful with content type 'comment' to get a whole thread).

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

Earliest date (UTC) in YYYY-MM-DD format.

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

Latest date (UTC, inclusive) in YYYY-MM-DD format.

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

Only return stories with at least this many points (ignored for comments).

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

Maximum number of results to return (up to 1000 per run, an API limit).

## Actor input object example

```json
{
  "query": "apify",
  "contentType": "story",
  "sortBy": "relevance",
  "maxItems": 100
}
```

# 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 = {
    "query": "apify",
    "contentType": "story",
    "sortBy": "relevance",
    "maxItems": 100
};

// Run the Actor and wait for it to finish
const run = await client.actor("mellora/hacker-news-stories-comments-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 = {
    "query": "apify",
    "contentType": "story",
    "sortBy": "relevance",
    "maxItems": 100,
}

# Run the Actor and wait for it to finish
run = client.actor("mellora/hacker-news-stories-comments-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 '{
  "query": "apify",
  "contentType": "story",
  "sortBy": "relevance",
  "maxItems": 100
}' |
apify call mellora/hacker-news-stories-comments-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,mellora/hacker-news-stories-comments-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/JxktWJjQz1JGwmUaV/builds/WFd6DLxAeayeFalea/openapi.json
