# Stack Overflow & Stack Exchange Scraper (`tidyharvest/stack-overflow-questions-scraper`) Actor

Search Stack Overflow and any Stack Exchange site by keyword, tag, score and date, browse a tag, or paste question URLs from any site. Each question has full text, tags, views and the top answers with the accepted one flagged. Many searches per run, each with its own cap. $2 per 1,000 questions.

- **URL**: https://apify.com/tidyharvest/stack-overflow-questions-scraper.md
- **Developed by:** [TidyHarvest](https://apify.com/tidyharvest) (community)
- **Categories:** Developer tools, AI
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$2.00 / 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 & Stack Exchange Scraper

Search **Stack Overflow** and any of the 170+ **Stack Exchange** sites (Server Fault, Super User, Ask Ubuntu, Math, Cooking, Law and more) and get **questions with their answers** as clean JSON. Filter by keyword, tags, minimum score, date range and accepted answer, and sort by votes, activity or newest. Every question comes with the full text (plain text and original HTML), score, views, tags, author and link, plus the top answers with the accepted answer flagged. Mix many searches and question URLs from different sites in one run; each search gets its own cap and a run total is shared fairly between them. No login needed, and runs finish in seconds. **$2.00 per 1,000 questions, answers included.**

### What you can do with it

- **Build Q\&A datasets for LLMs and RAG:** export high-score questions with accepted answers for a topic or tag, with license info per item.
- **Developer-demand research:** find the most-viewed unanswered or high-vote questions in a tag to spot what people struggle with.
- **Support and docs gap analysis:** monitor questions about your product or library on a schedule (sort by newest, filter by tag).
- **Competitor and technology tracking:** watch how a framework's question volume and scores change over time.
- **Look up specific threads:** paste question URLs or ids and get each one with its answers.

### Input

| Field | What it does |
|---|---|
| `queries` | Search texts, question URLs, answer URLs or question ids, one per line. URLs from any Stack Exchange site (superuser.com, math.stackexchange.com, ...) use their own site. Leave empty to browse `tags`. |
| `tags` | Only questions that have all of these tags. With no `queries`, the run browses these tags. |
| `site` | Site for searches and tag browsing, default `stackoverflow` (`serverfault`, `superuser`, `askubuntu`, `math`, `cooking`, ... or the site address). |
| `sort`, `order` | `relevance` (default, best with search text), `votes`, `activity`, `creation`; `desc` or `asc`. |
| `maxPerQuery` | Most questions per search line (or for the tag browse). Default 100. A question URL or id returns its one question. |
| `maxItems` | Cap on questions for the whole run (and your cost), shared fairly across all lines. Empty = no total cap. |
| `minScore` | Drop searched questions below this score. |
| `onlyWithAcceptedAnswer` | Keep only searched questions that have an accepted answer. |
| `fromDate`, `toDate` | Question creation date window, `YYYY-MM-DD` (UTC). |
| `includeAnswers`, `maxAnswers` | Add the top answers (accepted first, then by score) inside each question; default 3, set 0 for questions only. |
| `keywords` | Keep a searched question only if its title, text or tags contain one of these words. |

Filters (`tags`, `minScore`, accepted answer, dates, `keywords`) apply to searches and tag browsing; a question URL or id always returns that question. The same question found by two lines is returned (and charged) once.

Examples:

```json
{ "queries": ["python asyncio gather", "pandas merge on multiple columns", "https://superuser.com/questions/1"], "sort": "votes", "minScore": 20, "maxPerQuery": 50, "maxItems": 120 }
```

```json
{ "tags": ["pandas"], "sort": "votes", "maxPerQuery": 20 }
```

### Output

One item per question:

```json
{
  "question_id": 27435284, "site": "stackoverflow", "url": "https://stackoverflow.com/questions/27435284/...", "query": "python asyncio gather",
  "title": "multiprocessing vs multithreading vs asyncio", "tags": ["python", "python-asyncio"],
  "score": 399, "view_count": 220812, "answer_count": 13, "is_answered": true, "accepted_answer_id": 27436735,
  "created": "2014-12-12T01:23:57Z", "last_activity": "2024-11-10T06:30:27Z", "author": "...", "author_reputation": 6423,
  "license": "CC BY-SA 4.0", "body_html": "<p>...</p>", "body_text": "...",
  "answers": [{"answer_id": 27436735, "is_accepted": true, "score": 520, "author": "...", "body_text": "...", "body_html": "...", "url": "https://stackoverflow.com/a/27436735"}],
  "accepted_answer": {"answer_id": 27436735, "...": "..."}
}
```

`query` is the input line that returned the question (empty for a tag browse). The run's `SUMMARY` record lists, for every line, how many questions matched on the site (`found`), how many were returned, duplicates skipped and whether more were available, plus any line that failed (for example an unknown site name).

### Pricing

Pay per result: **$2.00 per 1,000 questions** (`question-scraped`). Answers are included in the question item at no extra charge. Filters and caps apply before you are charged. A run that finds nothing fails instead of silently returning an empty dataset.

### Limits and notes

- A search with no matches returns nothing for that line and the rest of the run carries on; the run fails only if every line failed or nothing matched at all.
- Very large exports can reach Stack Exchange's daily request limit. The run then stops cleanly with what it already collected and says so in its status; run again later for more.
- Each search returns at most 10,000 questions; split a bigger export by tag or date range.
- Content is user-contributed under Creative Commons (CC BY-SA); each item includes its `license`. Keep attribution if you republish it.
- Public data only. Not affiliated with Stack Exchange, Inc.

# Actor input Schema

## `queries` (type: `array`):

One per line: free-text search (title and body), a question URL, an answer URL or a question ID. URLs from any Stack Exchange site work and use their own site, so you can mix them with searches. Leave empty to browse the tags below.

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

Only questions that have ALL these tags, e.g. python, pandas. Applies to every search; with no search text, the run browses these tags.

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

Site for searches and tag browsing: stackoverflow, superuser, serverfault, askubuntu, math, unix, cooking, ... or the site's address (e.g. math.stackexchange.com). Question URLs always use their own site.

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

Relevance (best with search text), votes, recent activity or creation date.

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

Sort direction.

## `maxPerQuery` (type: `integer`):

Most questions to return for each search line (or for the tag browse). A question URL or ID returns its one question.

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

Cap on questions for the whole run (and your cost), shared fairly across all lines. Empty or 0 = no total cap.

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

Only searched questions with at least this many votes.

## `onlyWithAcceptedAnswer` (type: `boolean`):

Only searched questions that have an accepted answer.

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

Only questions created on or after this day (UTC), e.g. 2024-01-01.

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

Only questions created on or before this day (UTC), e.g. 2024-12-31.

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

Adds the top answers (accepted answer first) inside each question. Included in the question price.

## `maxAnswers` (type: `integer`):

Answers kept per question: the accepted one first, then the highest scored. 0 = questions only.

## `keywords` (type: `array`):

Keep a searched question only if its title, text or tags contain one of these. Empty = all.

## Actor input object example

```json
{
  "queries": [
    "python asyncio gather"
  ],
  "site": "stackoverflow",
  "sort": "relevance",
  "order": "desc",
  "maxPerQuery": 20,
  "onlyWithAcceptedAnswer": false,
  "includeAnswers": true,
  "maxAnswers": 3
}
```

# Actor output Schema

## `questions` (type: `string`):

One item per question, with its top answers.

## `summary` (type: `string`):

Matches found and questions returned for each search line, and any line that failed.

# 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 = {
    "queries": [
        "python asyncio gather"
    ],
    "site": "stackoverflow",
    "maxPerQuery": 20
};

// Run the Actor and wait for it to finish
const run = await client.actor("tidyharvest/stack-overflow-questions-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 = {
    "queries": ["python asyncio gather"],
    "site": "stackoverflow",
    "maxPerQuery": 20,
}

# Run the Actor and wait for it to finish
run = client.actor("tidyharvest/stack-overflow-questions-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 '{
  "queries": [
    "python asyncio gather"
  ],
  "site": "stackoverflow",
  "maxPerQuery": 20
}' |
apify call tidyharvest/stack-overflow-questions-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,tidyharvest/stack-overflow-questions-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/XaRvVJf7HfadwfSfC/builds/kEP5Fk0aIFCGWEzvv/openapi.json
