# Stack Overflow Q\&A Scraper (`sheshinmcfly/stackoverflow-scraper`) Actor

Extract questions and answers from Stack Overflow via the official Stack Exchange API. Filter by tags, keywords, or top voted. Returns question body, accepted answer, top answers, vote counts, and tags. Perfect for AI training data, RAG pipelines, and knowledge bases.

- **URL**: https://apify.com/sheshinmcfly/stackoverflow-scraper.md
- **Developed by:** [Sheshinmcfly](https://apify.com/sheshinmcfly) (community)
- **Categories:** AI, Developer tools, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 1 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 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 Q&A Scraper

Extract **questions and answers from Stack Overflow** via the official Stack Exchange API. Filter by tags, search by keywords, or get the top-voted questions of all time. Returns full question body, accepted answer, and top answers.

Perfect for AI training datasets, technical knowledge bases, RAG pipelines, and building Q&A chatbots.

---

### What data does it extract?

#### Questions

| Field | Description | Example |
|---|---|---|
| `questionId` | Stack Overflow question ID | `11227809` |
| `title` | Question title | `"What does the yield keyword do?"` |
| `body` | Full question body (HTML) | `"<p>I'm trying to understand..."` |
| `tags` | Associated tags | `["python", "generator", "yield"]` |
| `score` | Net upvotes | `13133` |
| `viewCount` | Number of views | `4200000` |
| `answerCount` | Total number of answers | `32` |
| `isAnswered` | Has an accepted answer | `true` |
| `author` | Question author username | `"e-satis"` |
| `createdAt` | Question creation date | `"2012-03-15T10:00:00Z"` |
| `url` | Direct link | `"https://stackoverflow.com/q/11227809"` |
| `answers` | Array of top answers | `[...]` |
| `extractedAt` | Extraction timestamp | `"2026-04-21T12:00:00Z"` |

#### Answers (nested)

| Field | Description | Example |
|---|---|---|
| `answerId` | Answer ID | `231855` |
| `author` | Answer author | `"e-satis"` |
| `score` | Net upvotes | `18307` |
| `isAccepted` | Accepted by question author | `true` |
| `body` | Full answer body (HTML) | `"<p>To understand what yield does..."` |
| `createdAt` | Answer creation date | `"2012-03-15T10:30:00Z"` |
| `url` | Direct answer link | `"https://stackoverflow.com/a/231855"` |

---

### Use cases

- **AI training data**: High-quality problem/solution pairs for LLM fine-tuning
- **RAG pipelines**: Build a Q&A bot that answers based on real Stack Overflow solutions
- **Technical knowledge base**: Export answers for a specific technology stack
- **Developer tools**: Power autocomplete or search features with curated Q&A
- **Research**: Analyze how developers solve specific problems
- **Chatbot training**: Create domain-specific support bots

---

### How to use

1. Open the actor and configure:
   - **Mode**: By tags, keyword search, or top voted all-time
   - **Tags**: e.g. `python`, `javascript`, `docker`, `react`
   - **Keywords**: e.g. `"how to reverse a list in python"`
   - **Site**: Stack Overflow, Super User, Server Fault, etc.
   - **Include answers**: Fetch top answers for each question
   - **API key**: Optional — increases daily quota from 300 to 10,000 requests
2. Click **Start**
3. Download results as JSON, CSV, or Excel

---

### API Key (optional)

The Stack Exchange API allows 300 free requests/day without authentication. To increase this to **10,000 requests/day**, register a free app at [stackapps.com](https://stackapps.com) and paste the key in the `apiKey` field.

---

### Example output (JSON)

```json
{
  "questionId": 231767,
  "title": "What does the \"yield\" keyword do in Python?",
  "body": "<p>What is the use of the <code>yield</code> keyword in Python?...",
  "tags": ["python", "iterator", "generator", "yield"],
  "score": 13133,
  "viewCount": 4200000,
  "answerCount": 32,
  "isAnswered": true,
  "author": "e-satis",
  "createdAt": "2008-10-23T22:21:01.000Z",
  "url": "https://stackoverflow.com/questions/231767/what-does-the-yield-keyword-do-in-python",
  "answers": [
    {
      "answerId": 231855,
      "author": "e-satis",
      "score": 18307,
      "isAccepted": true,
      "body": "<p>To understand what <code>yield</code> does, you must understand what generators are...",
      "createdAt": "2008-10-23T22:48:54.000Z",
      "url": "https://stackoverflow.com/a/231855"
    }
  ],
  "extractedAt": "2026-04-21T12:00:00.000Z"
}
````

***

### Pricing

This actor charges **$0.002 USD per question extracted**. Extracting 100 questions (with answers) costs approximately $0.20 USD.

***

### Keywords

stackoverflow scraper, stack overflow Q\&A extractor, technical Q\&A dataset, stack exchange API scraper, developer knowledge base, AI training data, programming Q\&A, stack overflow answers, RAG dataset, LLM fine-tuning data

***

### Legal Disclaimer

This actor extracts **publicly available data only** from Stack Overflow and Stack Exchange sites using the **official Stack Exchange API v2.3**, in compliance with Chilean Law 19.628 on the Protection of Private Life (*Ley 19.628 sobre Protección de la Vida Privada*).

All content on Stack Exchange is licensed under [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/). Users are responsible for complying with attribution requirements when using extracted content.

**What this actor does NOT collect:**

- Private messages or non-public content
- User emails, passwords, or private account information
- Any data not freely accessible via the public API

**What this actor collects:**

- Question titles, bodies, and tags (public content)
- Publicly visible usernames and answer text
- Engagement metrics (scores, view counts)

Users are solely responsible for ensuring their use of this data complies with applicable laws and Stack Exchange's terms of service.

# Actor input Schema

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

How to find questions: by tags, by keyword search, or top voted all-time.

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

Filter questions by tags (used when mode is 'By tags'). E.g. python, javascript, docker.

## `keywords` (type: `string`):

Search query (used when mode is 'By keyword search'). E.g. 'how to reverse a list in python'.

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

Which Stack Exchange site to query.

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

How to sort the questions.

## `onlyAnswered` (type: `boolean`):

Skip questions with no accepted answer.

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

Also fetch the top answers for each question.

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

Maximum number of answers to fetch per question.

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

Maximum number of questions to extract.

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

Optional API key to increase quota from 300 to 10,000 requests/day. Get one free at stackapps.com.

## Actor input object example

```json
{
  "mode": "tags",
  "tags": [
    "python"
  ],
  "keywords": "",
  "site": "stackoverflow",
  "sortBy": "votes",
  "onlyAnswered": true,
  "includeAnswers": true,
  "maxAnswersPerQuestion": 3,
  "maxResults": 50,
  "apiKey": ""
}
```

# Actor output Schema

## `dataset` (type: `string`):

All scraped Stack Overflow questions stored in the default dataset.

# 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("sheshinmcfly/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 = {}

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

```

## MCP server setup

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

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Stack Overflow Q&A Scraper",
        "description": "Extract questions and answers from Stack Overflow via the official Stack Exchange API. Filter by tags, keywords, or top voted. Returns question body, accepted answer, top answers, vote counts, and tags. Perfect for AI training data, RAG pipelines, and knowledge bases.",
        "version": "1.0",
        "x-build-id": "DEuFbfTQ67wBGzqHr"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/sheshinmcfly~stackoverflow-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-sheshinmcfly-stackoverflow-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/sheshinmcfly~stackoverflow-scraper/runs": {
            "post": {
                "operationId": "runs-sync-sheshinmcfly-stackoverflow-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/sheshinmcfly~stackoverflow-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-sheshinmcfly-stackoverflow-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",
                "properties": {
                    "mode": {
                        "title": "Mode",
                        "enum": [
                            "tags",
                            "search",
                            "top"
                        ],
                        "type": "string",
                        "description": "How to find questions: by tags, by keyword search, or top voted all-time.",
                        "default": "tags"
                    },
                    "tags": {
                        "title": "Tags",
                        "type": "array",
                        "description": "Filter questions by tags (used when mode is 'By tags'). E.g. python, javascript, docker.",
                        "items": {
                            "type": "string"
                        },
                        "default": [
                            "python"
                        ]
                    },
                    "keywords": {
                        "title": "Search keywords",
                        "type": "string",
                        "description": "Search query (used when mode is 'By keyword search'). E.g. 'how to reverse a list in python'.",
                        "default": ""
                    },
                    "site": {
                        "title": "Stack Exchange site",
                        "enum": [
                            "stackoverflow",
                            "superuser",
                            "serverfault",
                            "askubuntu",
                            "unix"
                        ],
                        "type": "string",
                        "description": "Which Stack Exchange site to query.",
                        "default": "stackoverflow"
                    },
                    "sortBy": {
                        "title": "Sort by",
                        "enum": [
                            "votes",
                            "activity",
                            "creation",
                            "relevance"
                        ],
                        "type": "string",
                        "description": "How to sort the questions.",
                        "default": "votes"
                    },
                    "onlyAnswered": {
                        "title": "Only answered questions",
                        "type": "boolean",
                        "description": "Skip questions with no accepted answer.",
                        "default": true
                    },
                    "includeAnswers": {
                        "title": "Include answers",
                        "type": "boolean",
                        "description": "Also fetch the top answers for each question.",
                        "default": true
                    },
                    "maxAnswersPerQuestion": {
                        "title": "Max answers per question",
                        "minimum": 1,
                        "maximum": 10,
                        "type": "integer",
                        "description": "Maximum number of answers to fetch per question.",
                        "default": 3
                    },
                    "maxResults": {
                        "title": "Max questions",
                        "minimum": 1,
                        "maximum": 500,
                        "type": "integer",
                        "description": "Maximum number of questions to extract.",
                        "default": 50
                    },
                    "apiKey": {
                        "title": "Stack Exchange API key (optional)",
                        "type": "string",
                        "description": "Optional API key to increase quota from 300 to 10,000 requests/day. Get one free at stackapps.com.",
                        "default": ""
                    }
                }
            },
            "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
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
