# Stack Overflow Scraper | Incremental, No API Key Needed (`hridayrungta/stackoverflow-scraper`) Actor

Questions and answers from the official Stack Exchange API - no login, no browser. Incremental mode returns only what's new since your last run, filtered server-side by date. Filter by tag or keyword; full question and answer bodies, scores, owners. $0.60 per 1,000 rows.

- **URL**: https://apify.com/hridayrungta/stackoverflow-scraper.md
- **Developed by:** [Hriday Rungta](https://apify.com/hridayrungta) (community)
- **Categories:** Developer tools, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.60 / 1,000 question scrapeds

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

## Stack Overflow Scraper — incremental, no API key needed

**Give it a tag, a keyword, or both, and get questions and answers back** — no login, no
browser. Turn on incremental mode and every run after the first returns only what's new since the
previous one, filtered server-side by Stack Exchange's own API.

**$0.60 per 1,000 rows.** No start fee. The top-ranked competing Stack Overflow Actor on the
Store charges $3.50–5.00 per 1,000 — this reads the same official public API, with nothing extra
behind it that costs more to run.

***

### What you get

One row per question:

| | |
|---|---|
| `questionId`, `title`, `bodyHtml`, `tags` | the question and its full body |
| `score`, `viewCount`, `answerCount`, `isAnswered` | how it did |
| `ownerName`, `ownerUserId`, `ownerReputation` | who asked |
| `createdUtc`, `createdAtIso`, `link` | exact time and a direct link |

Turn on **Also scrape answers** and every answer becomes its own row with `answerId`,
`questionId`, `bodyHtml`, `score`, `isAccepted` and its own owner fields — fetched in batches of
up to 100 questions per request, not one request per answer.

### Incremental mode: simpler here than anywhere else in this developer's portfolio

Every other incremental Actor here (Reddit, LinkedIn Jobs) has to implement its own "stop paging
once you reach ground you've already covered" logic, because the underlying site gives no
built-in way to ask for only-what's-new. Stack Exchange's API is different: it accepts a
`fromdate` parameter and filters **server-side**. So `mode: "changes"` here is not a heuristic -
it is literally asking the API for exactly what changed, and the API answers exactly that.

- **First run never bills your whole tag's history.** It seeds from `firstRunSince` (30 days by
  default) rather than the beginning of the tag's archive. Pass `"all"` for a deliberate backfill.
- **The mark advances only from what this run actually emitted, and always advances even on a
  capped run** - the same rule this developer's Reddit Actor learned the hard way (a mark that
  only advances on an uncapped run can end up never advancing at all for a busy source).

### The API quota, and why an API key is optional but useful

Stack Exchange gives every anonymous caller a shared 300-requests/day quota. Since each request
here can return up to 100 rows, that is a lot of rows before it matters - but if you run this
Actor often or on many tags, register a free key at stackapps.com (instant, no approval wait) and
paste it into **Stack Apps API key**: the same account's quota jumps to 10,000 requests/day.

### Input at a glance

| Input | Default | Notes |
|---|---|---|
| `tags` | — | AND-matched; leave empty to use `query` alone or pull the unfiltered firehose |
| `query` | — | full-text search, combinable with tags |
| `mode` | `all` | `all` or `changes` |
| `sort` | `creation` | `all` mode only; `changes` mode always uses `creation` |
| `includeAnswers` | `false` | batched, up to 100 questions per request |
| `minScore` | `0` | drops questions and answers scoring below this |
| `maxItems` | `200` | cost cap — billed once per row saved |
| `firstRunSince` | `30 days` | `changes` mode only |
| `apiKey` | — | optional, see above |

### Billing

Pay per event, charged once per row saved, **no start fee**:

| Event | Price | When |
|---|---|---|
| `question-scraped` | $0.0006 | one question row |
| `answer-scraped` | $0.0006 | one answer row |

Set `maxItems` as your cost cap.

# Actor input Schema

## `site` (type: `string`):

Any Stack Exchange site's API name (e.g. "stackoverflow", "superuser", "serverfault", "askubuntu").

## `tags` (type: `array`):

Filter questions to these tags (AND match). Leave empty for no tag filter.

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

Full-text search phrase. Combine with tags to narrow further, or use alone.

## `mode` (type: `string`):

"all": every matching question, every run. "changes": only what's new since your last run for this exact tag/query source.

## `sort` (type: `string`):

Listing order. Incremental mode overrides this to "creation" regardless of what is set here.

## `includeAnswers` (type: `boolean`):

Fetch every answer for every matched question, batched up to 100 questions per request.

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

Drop questions and answers scoring below this. Leave blank for no floor.

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

Cost cap - you're billed once per row saved.

## `firstRunSince` (type: `string`):

A source's first incremental run only takes questions created since this date/span - never the site's whole history. Default "30 days"; "all" for a deliberate backfill.

## `apiKey` (type: `string`):

Free, instant registration at stackapps.com. Without one, requests share a 300/day pool; with one, 10,000/day.

## `maxRetries` (type: `integer`):

Retries with backoff for network errors, throttling and 5xx responses.

## `stateStoreName` (type: `string`):

Name of the key-value store (in YOUR account) that holds the high-water mark per source. Leave blank for the default.

## `stateNamespace` (type: `string`):

Advanced: an explicit namespace for the mark key. Leave blank to namespace by your Apify user id automatically.

## Actor input object example

```json
{
  "site": "stackoverflow",
  "tags": [
    "javascript"
  ],
  "query": "",
  "mode": "all",
  "sort": "creation",
  "includeAnswers": false,
  "minScore": 0,
  "maxItems": 200,
  "firstRunSince": "30 days",
  "maxRetries": 3,
  "stateStoreName": "",
  "stateNamespace": ""
}
```

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

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

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

```

## MCP server setup

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