# StackOverflow Scraper - Questions, Answers & Tags (`makework36/stackoverflow-scraper`) Actor

Scrape StackOverflow and any StackExchange site. Fetch hot questions, search by query, or filter by tags. Pure HTTP via the official StackExchange API v2.3.

- **URL**: https://apify.com/makework36/stackoverflow-scraper.md
- **Developed by:** [deusex machine](https://apify.com/makework36) (community)
- **Categories:** Developer tools
- **Features:** Limited permissions
- **Stats:** 6 total users, 0 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.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/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

## StackOverflow Scraper

Scrape questions from StackOverflow and any StackExchange site. Get hot questions, search by topic, or filter by tags. Returns titles, scores, view counts, answers, and body excerpts. Uses the official StackExchange API v2.3 -- no browser needed.

### What data does it extract?

| Field | Description |
|-------|-------------|
| `questionId` | Unique question ID |
| `title` | Question title |
| `link` | Full URL to the question page |
| `score` | Net vote score (upvotes minus downvotes) |
| `answerCount` | Number of answers |
| `viewCount` | Total view count |
| `isAnswered` | Whether the question has an accepted or upvoted answer |
| `tags` | List of tags (e.g. `["python", "pandas"]`) |
| `owner.name` | Author's display name |
| `owner.reputation` | Author's reputation score |
| `creationDate` | When the question was posted (ISO 8601) |
| `lastActivityDate` | Last activity timestamp (ISO 8601) |
| `body` | Question body text (HTML stripped) |

### 🎯 Use cases

- **Developer trend tracking** -- Monitor which technologies are trending based on question volume and votes.
- **Content creation** -- Find popular questions to create blog posts, tutorials, or YouTube videos around.
- **Knowledge base building** -- Pull top-voted questions and answers for internal team wikis.
- **Competitive analysis** -- Compare question activity across competing frameworks or libraries.
- **Research datasets** -- Build datasets of programming Q\&A data for NLP or ML projects.

### 🚀 How to use

Get trending hot questions:

```json
{
    "mode": "hot",
    "maxResults": 20
}
```

Search for a specific topic:

```json
{
    "mode": "search",
    "searchQuery": "async await best practices",
    "sort": "relevance",
    "maxResults": 50
}
```

Filter by tags, sorted by votes:

```json
{
    "mode": "tagged",
    "tags": ["python", "pandas"],
    "sort": "votes",
    "maxResults": 100
}
```

Query a different StackExchange site:

```json
{
    "mode": "hot",
    "site": "serverfault",
    "maxResults": 10
}
```

### 📥 Input

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `mode` | enum | `hot` | `hot` for trending, `search` for text query, `tagged` for tag filter |
| `searchQuery` | string | `""` | Text query (only for `search` mode) |
| `tags` | string\[] | `[]` | Tags to filter by (required for `tagged`, optional for `search`) |
| `site` | string | `stackoverflow` | Any StackExchange site slug (e.g. `serverfault`, `askubuntu`, `superuser`) |
| `maxResults` | integer | `50` | Max questions to return (1-250) |
| `sort` | enum | `hot` | Sort by: `activity`, `votes`, `creation`, `hot`, or `relevance` (search only) |

### 📋 Output example

```json
{
    "questionId": 71382145,
    "title": "What is the fastest way to flatten a list in Python 3.12+?",
    "link": "https://stackoverflow.com/questions/71382145/what-is-the-fastest-way-to-flatten-a-list-in-python",
    "score": 847,
    "answerCount": 12,
    "viewCount": 234019,
    "isAnswered": true,
    "tags": ["python", "list", "performance", "python-3.x"],
    "owner": {
        "name": "alex_dev",
        "reputation": 15420
    },
    "creationDate": "2024-03-05T18:22:31.000Z",
    "lastActivityDate": "2026-02-14T09:15:02.000Z",
    "body": "I have a list of lists and need to flatten it into a single list. I've tried itertools.chain, sum(), and list comprehensions but I'm not sure which is fastest for large lists..."
}
```

### ⚡ Performance

- Fetches 100 questions per API call with automatic pagination. A full run of 250 questions uses 3 API requests.
- The StackExchange API allows 300 requests/day without an API key. Quota-aware -- stops before exhausting your limit.
- No browser needed. A typical run completes in under 5 seconds and costs under $0.005 in platform credits.

### ❓ FAQ

**Can I scrape answers too?**
This actor focuses on questions. Answer content is not included in the output, only the answer count.

**What's the API quota?**
300 requests per day without an API key, shared across your IP. With `pagesize=100`, a single run of 250 questions uses only 3 requests.

**What StackExchange sites can I use?**
Any site in the network: `stackoverflow`, `serverfault`, `superuser`, `askubuntu`, `mathoverflow`, and dozens more. Use the site slug from the URL.

**Why does sort "relevance" only work in search mode?**
The StackExchange API only supports relevance sorting when a search query is provided. In other modes, use `hot`, `votes`, `activity`, or `creation`.

# Changelog

This Actor's version history is a separate document: https://apify.com/makework36/stackoverflow-scraper/changelog.md

# Actor input Schema

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

Scraping mode: 'hot' fetches trending questions, 'search' uses a text query, 'tagged' filters by tags.

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

Text query for search mode. Only used when mode is 'search'.

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

Tags to filter by (e.g. \['javascript', 'react']). Used in 'tagged' mode, optional in 'search' mode.

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

The StackExchange site to query (e.g. 'stackoverflow', 'serverfault', 'askubuntu').

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

Maximum number of questions to return (1-250). The API quota is 300 requests/day for anonymous usage.

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

How to sort the results. 'relevance' only works in search mode.

## Actor input object example

```json
{
  "mode": "hot",
  "searchQuery": "",
  "tags": [],
  "site": "stackoverflow",
  "maxResults": 50,
  "sort": "hot"
}
```

# Actor output Schema

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

All scraped items in the default dataset (JSON).

## `csv` (type: `string`):

Default dataset formatted as CSV for spreadsheets (Google Sheets, Excel).

# 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 = {
    "mode": "hot",
    "site": "stackoverflow",
    "maxResults": 50,
    "sort": "hot"
};

// Run the Actor and wait for it to finish
const run = await client.actor("makework36/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 = {
    "mode": "hot",
    "site": "stackoverflow",
    "maxResults": 50,
    "sort": "hot",
}

# Run the Actor and wait for it to finish
run = client.actor("makework36/stackoverflow-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 '{
  "mode": "hot",
  "site": "stackoverflow",
  "maxResults": 50,
  "sort": "hot"
}' |
apify call makework36/stackoverflow-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,makework36/stackoverflow-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/P6Qyx9DAY3IWtsjx6/builds/Chzld0bq2MdfteShS/openapi.json
