# Stack Overflow Scraper — Question & Answer Data Extractor (`klondikeking/stack-overflow-scraper`) Actor

Extract Stack Overflow questions, answers, comments, and user profiles via the official Stack Exchange API. No scraping needed — fast, reliable, and cost-effective.

- **URL**: https://apify.com/klondikeking/stack-overflow-scraper.md
- **Developed by:** [Pierrick McD0nald](https://apify.com/klondikeking) (community)
- **Categories:** Developer tools, Business
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, NaN 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/platform/actors/running/actors-in-store#pay-per-usage

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

## Stack Overflow Scraper — Question & Answer Data Extractor

Extract Stack Overflow questions, answers, comments, and user profile data using the official Stack Exchange API. This Actor is fast, reliable, and requires no browser rendering or proxy overhead — making it one of the most cost-effective ways to gather developer-focused data from the world's largest Q&A community.

### Use Cases

- **Developer research** — Track trending topics, popular frameworks, and emerging technologies by analyzing question volume and tags over time.
- **Content marketing** — Identify high-traffic questions in your niche to create blog posts, tutorials, or documentation that answers real developer pain points.
- **Competitive intelligence** — Monitor how often competitors, libraries, or tools are mentioned in Stack Overflow discussions.
- **Support automation** — Build knowledge bases by extracting answered questions and their accepted solutions for internal documentation.
- **Academic & NLP datasets** — Collect structured Q&A pairs for training language models, sentiment analysis, or topic modeling research.

### Input

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `searchQuery` | String | Yes | Search term to find questions (e.g. `javascript async await`, `python pandas dataframe`) |
| `tags` | Array | No | Filter questions to only those matching all specified tags (e.g. `["python", "machine-learning"]`) |
| `sort` | String | No | Sort order: `relevance`, `creation`, `votes`, or `activity` (default: `relevance`) |
| `maxItems` | Integer | No | Maximum number of questions to extract, from 1 to 1000 (default: 100) |
| `includeAnswers` | Boolean | No | Whether to fetch top-voted answers for each extracted question (default: false) |
| `maxAnswersPerQuestion` | Integer | No | Maximum answers to include per question when `includeAnswers` is true (default: 3, max: 10) |
| `proxyConfiguration` | Object | No | Proxy settings for outgoing requests |

### Output

The Actor outputs a dataset where each item represents a Stack Overflow question with the following fields:

```json
{
  "questionId": 12345678,
  "title": "How to use async/await in JavaScript?",
  "body": "I am trying to understand async/await...",
  "link": "https://stackoverflow.com/questions/12345678/how-to-use-async-await-in-javascript",
  "score": 42,
  "viewCount": 15023,
  "answerCount": 5,
  "tags": ["javascript", "async-await", "es6"],
  "creationDate": "2023-01-15T08:30:00.000Z",
  "lastActivityDate": "2024-03-10T14:22:00.000Z",
  "isAnswered": true,
  "owner": {
    "userId": 9876543,
    "displayName": "JohnDoe",
    "reputation": 12500,
    "profileLink": "https://stackoverflow.com/users/9876543/johndoe"
  },
  "answers": [
    {
      "answerId": 87654321,
      "body": "You can use async/await like this...",
      "score": 35,
      "isAccepted": true,
      "creationDate": "2023-01-15T09:15:00.000Z",
      "owner": {
        "userId": 1111111,
        "displayName": "JaneSmith",
        "reputation": 45000
      }
    }
  ]
}
````

### Pricing

Pay per event: **$0.001 per question extracted**. Answers are included at no extra charge when `includeAnswers` is enabled.

### Limitations

- The Stack Exchange API enforces rate limits: 300 requests per day without an API key, 10,000 per day with a free key. This Actor operates within the unauthenticated pool.
- Maximum 100 results per API page; large `maxItems` values may require multiple sequential requests.
- HTML bodies are sanitized to plain text; inline code and formatting are stripped.
- Very old or deleted questions may not appear in search results.

### FAQ

**Q: Do I need a Stack Overflow API key?**
A: No. This Actor uses the public Stack Exchange API without authentication for read-only operations.

**Q: Can I extract all answers for a question?**
A: The Actor fetches the top-voted answers up to the `maxAnswersPerQuestion` limit. To get all answers, increase the limit or run a dedicated answer extraction job.

**Q: Is the data real-time?**
A: The Stack Exchange API reflects the current state of the platform. Data is typically fresh within seconds of being posted.

### Changelog

- **v1.0.0** — Initial release. Search questions, filter by tags, optionally include answers.

# Actor input Schema

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

Search term to find Stack Overflow questions (e.g. 'javascript async', 'python pandas')

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

Only return questions with all of these tags (e.g. \['python', 'pandas'])

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

How to sort the results

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

Maximum number of questions to extract (1-1000)

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

Whether to include top answers for each question

## `maxAnswersPerQuestion` (type: `integer`):

Maximum answers to include per question (only if Include Answers is true)

## `proxyConfiguration` (type: `object`):

Proxy settings for outgoing requests

## Actor input object example

```json
{
  "searchQuery": "javascript",
  "tags": [
    "javascript"
  ],
  "sort": "relevance",
  "maxItems": 10,
  "includeAnswers": false,
  "maxAnswersPerQuestion": 3,
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}
```

# Actor output Schema

## `results` (type: `string`):

No description

## `stats` (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 = {
    "searchQuery": "javascript",
    "tags": [
        "javascript"
    ],
    "sort": "relevance",
    "maxItems": 10,
    "includeAnswers": false,
    "maxAnswersPerQuestion": 3,
    "proxyConfiguration": {
        "useApifyProxy": true
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("klondikeking/stack-overflow-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 = {
    "searchQuery": "javascript",
    "tags": ["javascript"],
    "sort": "relevance",
    "maxItems": 10,
    "includeAnswers": False,
    "maxAnswersPerQuestion": 3,
    "proxyConfiguration": { "useApifyProxy": True },
}

# Run the Actor and wait for it to finish
run = client.actor("klondikeking/stack-overflow-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 '{
  "searchQuery": "javascript",
  "tags": [
    "javascript"
  ],
  "sort": "relevance",
  "maxItems": 10,
  "includeAnswers": false,
  "maxAnswersPerQuestion": 3,
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}' |
apify call klondikeking/stack-overflow-scraper --silent --output-dataset

```

## MCP server setup

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

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Stack Overflow Scraper — Question & Answer Data Extractor",
        "description": "Extract Stack Overflow questions, answers, comments, and user profiles via the official Stack Exchange API. No scraping needed — fast, reliable, and cost-effective.",
        "version": "1.0",
        "x-build-id": "sVrpCyTIQhSn9dZ6K"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/klondikeking~stack-overflow-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-klondikeking-stack-overflow-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/klondikeking~stack-overflow-scraper/runs": {
            "post": {
                "operationId": "runs-sync-klondikeking-stack-overflow-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/klondikeking~stack-overflow-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-klondikeking-stack-overflow-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": [
                    "searchQuery"
                ],
                "properties": {
                    "searchQuery": {
                        "title": "Search Query",
                        "type": "string",
                        "description": "Search term to find Stack Overflow questions (e.g. 'javascript async', 'python pandas')"
                    },
                    "tags": {
                        "title": "Filter by Tags",
                        "type": "array",
                        "description": "Only return questions with all of these tags (e.g. ['python', 'pandas'])",
                        "items": {
                            "type": "string"
                        }
                    },
                    "sort": {
                        "title": "Sort Order",
                        "enum": [
                            "relevance",
                            "creation",
                            "votes",
                            "activity"
                        ],
                        "type": "string",
                        "description": "How to sort the results",
                        "default": "relevance"
                    },
                    "maxItems": {
                        "title": "Maximum Results",
                        "minimum": 1,
                        "maximum": 1000,
                        "type": "integer",
                        "description": "Maximum number of questions to extract (1-1000)",
                        "default": 100
                    },
                    "includeAnswers": {
                        "title": "Include Answers",
                        "type": "boolean",
                        "description": "Whether to include top answers for each question",
                        "default": false
                    },
                    "maxAnswersPerQuestion": {
                        "title": "Max Answers per Question",
                        "minimum": 1,
                        "maximum": 10,
                        "type": "integer",
                        "description": "Maximum answers to include per question (only if Include Answers is true)",
                        "default": 3
                    },
                    "proxyConfiguration": {
                        "title": "Proxy Configuration",
                        "type": "object",
                        "description": "Proxy settings for outgoing requests"
                    }
                }
            },
            "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
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
