# Stack Overflow & Stack Exchange Scraper (`ponderable_hydrometer/stackexchange-scraper`) Actor

Search Stack Overflow & any Stack Exchange site for questions — and their answers — by keyword, tags, votes. Free API, optional key for higher quota. For research & datasets.

- **URL**: https://apify.com/ponderable\_hydrometer/stackexchange-scraper.md
- **Developed by:** [Ponderable Hydrometer](https://apify.com/ponderable_hydrometer) (community)
- **Categories:** Developer tools, Automation, SEO tools
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 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 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

## Stack Overflow & Stack Exchange Scraper

**Search questions — and optionally their full answers — across Stack Overflow and any Stack Exchange site, by keyword, tags, votes or recency.** Includes question/answer bodies, scores and accepted flags. Free API (add a free key for 10,000 requests/day).

Ideal for LLM training datasets, technical research, dev-trend analysis and content pipelines — clean, structured Q\&A with the signals you filter on.

### What you get

**Questions** — one row per question:

- `questionId`, `title`, `link`, `score`, `viewCount`
- `answerCount`, `isAnswered`, `acceptedAnswerId`
- `tags`, `owner`, `body` (HTML), `createdAt`, `lastActivity`

**Answers** (when `includeAnswers: true`) — nested `answers[]`, each with `answerId`, `score`, `isAccepted`, `owner`, `body`, `createdAt`, `link`

### Output sample

```json
{
  "questionId": 12345678,
  "title": "How does async/await work with forEach?",
  "link": "https://stackoverflow.com/questions/12345678/…",
  "score": 842,
  "answerCount": 12,
  "isAnswered": true,
  "acceptedAnswerId": 12345699,
  "viewCount": 410233,
  "tags": ["javascript", "async-await", "foreach"],
  "owner": "jane_dev",
  "body": "<p>I have this loop…</p>",
  "createdAt": "2016-05-01T10:12:00.000Z",
  "lastActivity": "2024-11-03T08:40:00.000Z",
  "answers": [
    {
      "answerId": 12345699,
      "score": 1503,
      "isAccepted": true,
      "owner": "senior_dev",
      "body": "<p>forEach doesn't await…</p>",
      "createdAt": "2016-05-01T10:30:00.000Z",
      "link": "https://stackoverflow.com/a/12345699"
    }
  ]
}
```

### Input

| Field | Type | Default | Description |
|-------|------|---------|-------------|
| `query` | string | `async await` | Keywords in question title/body |
| `tags` | array | — | Restrict to these tags |
| `site` | string | `stackoverflow` | Site slug (`serverfault`, `superuser`, `askubuntu`, `math`, `datascience`, …) |
| `sort` | string | `votes` | `votes`, `creation`, `activity`, `relevance` |
| `order` | string | `desc` | `desc` or `asc` |
| `includeAnswers` | boolean | `false` | Also fetch each question's answers |
| `key` | string (secret) | — | Free Stack Apps key (300 → 10,000 req/day) |
| `maxResults` | integer | `100` | Cap on questions returned |

Provide a `query` and/or `tags`.

### Example input

```json
{
  "tags": ["rust", "async"],
  "site": "stackoverflow",
  "sort": "votes",
  "includeAnswers": true,
  "maxResults": 100
}
```

### Why this actor

- **Any Stack Exchange site** — not just Stack Overflow.
- **Questions + answers** — pull full answer bodies, scores and accepted flags for complete Q\&A pairs.
- **The signals you filter on** — votes, views, answer counts, tags and dates.
- **Quota-aware** — honours the API's backoff and stops before exhausting quota.

### Pricing

Pay per result — **$2.00 per 1,000 results** (one question = one result; answers add value). No subscription or platform fees.

### Related actors

- **Hacker News Scraper** — HN stories, comments and dev sentiment.
- **GitHub Search Scraper** — repos, users and issues.
- **Package Registry Scraper** — npm/PyPI/crates package intelligence.

### Notes & limits

- Data is the Stack Exchange API 2.3. Keyless use is capped at **300 requests/day per IP** — add a free Stack Apps key (kept secret) for **10,000/day**.
- Bodies are HTML (as stored by Stack Exchange).
- Content is licensed CC BY-SA by Stack Exchange contributors — attribute and use accordingly. This actor is an independent tool, not affiliated with Stack Exchange.

# Actor input Schema

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

Keywords to search in question titles/bodies, e.g. "async await forEach".

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

Restrict to questions with these tags, e.g. \["javascript","promise"].

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

Stack Exchange site slug, e.g. "stackoverflow", "serverfault", "superuser", "askubuntu", "math", "datascience".

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

votes, creation, activity or relevance.

## `order` (type: `string`):

"desc" or "asc".

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

Also fetch each question's answers (body + score + accepted). Uses more quota.

## `key` (type: `string`):

A free Stack Apps key raises the quota from 300 to 10000 requests/day. Kept secret.

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

Cap on number of questions returned.

## Actor input object example

```json
{
  "query": "async await",
  "site": "stackoverflow",
  "sort": "votes",
  "order": "desc",
  "includeAnswers": false,
  "maxResults": 100
}
```

# 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": "async await",
    "site": "stackoverflow"
};

// Run the Actor and wait for it to finish
const run = await client.actor("ponderable_hydrometer/stackexchange-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": "async await",
    "site": "stackoverflow",
}

# Run the Actor and wait for it to finish
run = client.actor("ponderable_hydrometer/stackexchange-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 '{
  "query": "async await",
  "site": "stackoverflow"
}' |
apify call ponderable_hydrometer/stackexchange-scraper --silent --output-dataset

```

## MCP server setup

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

```

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/acts/UctALPOzbi4HdjOYP/builds/0FFe332WUXR5aO8a3/openapi.json
