# Stack Overflow & Stack Exchange Questions (`grit-77/stackexchange-questions`) Actor

Stack Overflow and Stack Exchange questions scraper. Filter by tags or search text; export question fields and optional linked answer rows as JSON with source links and attribution.

- **URL**: https://apify.com/grit-77/stackexchange-questions.md
- **Developed by:** [Grit](https://apify.com/grit-77) (community)
- **Categories:** Developer tools, Education
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per event

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 & Stack Exchange Questions

Stack Overflow and Stack Exchange questions scraper returns public question records with tags, scores, body HTML, source links, and attribution. Stack Exchange questions API exports optional answer records linked by `questionId` from the selected site.

### What it does

Choose a Stack Exchange site and filter by tags or search text. Questions and answers are separate dataset rows; an answer links back through `questionId`. `maxItems` covers both kinds of rows and errors. Source ordering can change as posts are edited or scored.

### Input example

```json
{
  "site": "stackoverflow",
  "tags": [
    "python"
  ],
  "includeAnswers": true,
  "maxItems": 10
}
```

The example uses fields defined in the actor input schema. Other filters can be set in the Apify input form.

### Output fields

Examples below come from the first record in [sample_output.json](sample_output.json); long strings and arrays are shown as excerpts. Other modes and error rows can have different fields.

| Field | Type in sample | Example value |
|---|---|---|
| `type` | string | `"question"` |
| `site` | string | `"stackoverflow"` |
| `postId` | number | `231767` |
| `questionId` | number | `231767` |
| `answerId` | null | `null` |
| `title` | string | `"What does the \"yield\" keyword do in Python?"` |
| `url` | string | `"https://stackoverflow.com/questions/231767/what-does-the-yield-keyword-do-in-python"` |
| `questionUrl` | string | `"https://stackoverflow.com/questions/231767/what-does-the-yield-keyword-do-in-python"` |
| `tags` | array | `["python", "iterator", "generator", "yield"]` |
| `score` | number | `13135` |
| `viewCount` | number | `3500476` |
| `answerCount` | number | `51` |
| `isAnswered` | boolean | `true` |
| `isAccepted` | null | `null` |
| `acceptedAnswerId` | number | `231855` |
| `createdAt` | string | `"2008-10-23T22:21:11Z"` |
| `lastActivityAt` | string | `"2026-04-30T18:43:47Z"` |
| `lastEditedAt` | string | `"2024-03-24T04:11:22Z"` |
| `bodyHtml` | string | `"<p>What functionality does the <a href=\"https://docs.python.org/3/reference/simp…` |
| `authorId` | number | `18300` |
| `authorName` | string | `"Alex. S."` |
| `authorUrl` | string | `"https://stackoverflow.com/users/18300/alex-s"` |
| `contentLicense` | string | `"CC BY-SA 4.0"` |
| `licenseUrl` | string | `"https://creativecommons.org/licenses/by-sa/4.0/"` |
| `attribution` | object | `{"sourceUrl": "https://stackoverflow.com/questions/231767/what-does-the-yield-keyw…` |
| `warnings` | array | `[]` |
| `errors` | array | `[]` |

### Output example

A trimmed record copied from [sample_output.json](sample_output.json):

```json
{
  "type": "question",
  "site": "stackoverflow",
  "postId": 231767,
  "questionId": 231767,
  "title": "What does the \"yield\" keyword do in Python?",
  "url": "https://stackoverflow.com/questions/231767/what-does-the-yield-keyword-do-in-python",
  "tags": [
    "python",
    "iterator",
    "generator",
    "yield"
  ],
  "score": 13135,
  "contentLicense": "CC BY-SA 4.0",
  "licenseUrl": "https://creativecommons.org/licenses/by-sa/4.0/",
  "warnings": [],
  "errors": []
}
```

### FAQ

**What does the result limit count?** `maxItems` counts question, answer, and error rows together. `maxPages` also limits scanning, so a run may finish before reaching the row cap.

**Do I need a proxy or login?** No login or proxy is used. An optional Stack Exchange application API key can be supplied; API quotas still apply.

**How is pricing handled?** The proposed pay-per-event model charges $0.001 for each unique successful `question` or `answer` row. Error and duplicate rows have no custom event. The owner must configure those rates in Apify before publication.

**How are API rate limits handled?** Requests share a paced lane with a 0.2-second minimum interval. Transient failures get at most four attempts; the client honors API backoff, `Retry-After`, and quota exhaustion.

**How current are the posts?** Rows reflect the public Stack Exchange API at retrieval time. Scores, activity, page boundaries, and licenses can change; this actor does not recover deleted posts or revision history.

### Use with AI agents / MCP

After this actor is available to your account, configure it as an actor tool in the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp), or start a run through the [Apify API](https://docs.apify.com/api/v2) with the same input JSON. Give the agent the actor identifier and access through your Apify credentials. Read the completed run’s default dataset through the returned run or dataset reference, check error fields before using records, and keep source URLs with quoted data. Limit the input to the task the agent is answering.

### Source and reuse notes

Keep `url`, `authorName`, `authorUrl`, `contentLicense`, and `licenseUrl` with reused text. The API can omit author or license details; `warnings` flags those cases. The actor preserves the API license value without inferring an older revision license. See [Stack Overflow licensing](https://stackoverflow.com/help/licensing). Accepted answers and total answer counts can exceed the answer rows saved under the configured caps.

# Actor input Schema

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

API site code, e.g. stackoverflow, math, superuser, serverfault or meta.stackoverflow. One site per run.

## `search` (type: `string`):

Optional free-text official API search. All tags below must match. Leave blank to use the question listing.

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

Up to five tags, matched together (AND), e.g. python and pandas. Empty means no tag filter.

## `fromDate` (type: `string`):

Optional YYYY-MM-DD (UTC) or ISO timestamp with timezone. Filters question creation, even when sorting by activity.

## `toDate` (type: `string`):

Optional YYYY-MM-DD (inclusive through 23:59:59 UTC) or ISO timestamp with timezone.

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

Optional inclusive lower score bound. With votes sort sent to the API; other sorts filter results locally.

## `maxScore` (type: `integer`):

Optional inclusive upper score bound. Does not filter answer scores.

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

Activity, creation, votes, or relevance (requires search). Score bounds apply with any sort.

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

Ascending or descending question order. Concurrent answer workers can interleave dataset rows.

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

Export separate answer rows, in descending score order per question. Questions are always saved before their answers.

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

Per-question answer cap. Subject to the total maxItems cap; answers may be truncated.

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

Hard total dataset cap shared by questions, answers and uncharged error rows. Answer rows use the same budget.

## `concurrency` (type: `integer`):

Concurrent answer workers. API requests share a paced lane and honor server backoff and quota.

## `maxPages` (type: `integer`):

Caps question scan pages and answer pages per question. Without an API key the API may reject page >25. Each page has up to 100 posts.

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

Optional key belonging to your Stack Exchange application. No access token or login needed. Quotas still apply; do not share your input.

## Actor input object example

```json
{
  "site": "stackoverflow",
  "tags": [
    "python"
  ],
  "sort": "activity",
  "order": "desc",
  "includeAnswers": false,
  "maxAnswersPerQuestion": 10,
  "maxItems": 100,
  "concurrency": 2,
  "maxPages": 25
}
```

# Actor output Schema

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

Dataset containing questions, optional answers and per-item errors.

# 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": [
        "python"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("grit-77/stackexchange-questions").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": ["python"] }

# Run the Actor and wait for it to finish
run = client.actor("grit-77/stackexchange-questions").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": [
    "python"
  ]
}' |
apify call grit-77/stackexchange-questions --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,grit-77/stackexchange-questions"
        }
    }
}
```

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/o5imLPSafbktabfBF/builds/nqVwLVAggp5cM2QYo/openapi.json
