# Mastodon Scraper (`glassventures/mastodon-scraper`) Actor

Scrape posts from any Mastodon instance. Extract toots, profiles, trending posts, and search results. Export to JSON, CSV, Excel.

- **URL**: https://apify.com/glassventures/mastodon-scraper.md
- **Developed by:** [Glass Ventures](https://apify.com/glassventures) (community)
- **Categories:** Social media
- **Features:** Limited permissions
- **Stats:** 256 total users, 23 monthly users, 100.0% runs succeeded, 0 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/actors/running/actors-in-store.md#pay-per-usage

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

## Mastodon Scraper

Scrape posts from any Mastodon instance. Extract toots, profiles, trending posts, and search results with full metadata.

### What does Mastodon Scraper do?

Mastodon Scraper extracts posts (toots) from any Mastodon-compatible instance using the standard Mastodon REST API. It works with mastodon.social, fosstodon.org, hachyderm.io, and any other Mastodon or Mastodon-compatible server.

The actor can scrape posts from specific user profiles, search for posts by keyword, fetch the public timeline, or collect trending posts. All data is returned in a structured format with full metadata including engagement counts, media attachments, and hashtags.

Whether you're doing social media research, tracking conversations about specific topics across the fediverse, or analyzing engagement patterns, this actor provides the data you need without requiring any API keys or authentication.

### Use Cases

- **Social media researchers** -- Monitor conversations and trends across the fediverse
- **Data analysts** -- Analyze engagement patterns, posting frequency, and content trends on Mastodon
- **Journalists** -- Track public discourse and trending topics on decentralized social media
- **Developers** -- Collect Mastodon data for building dashboards, bots, or analytics tools
- **Marketing teams** -- Monitor brand mentions and sentiment across Mastodon instances

### Features

- Scrape posts from any Mastodon-compatible instance
- Extract user profile posts by URL
- Search for posts by keyword
- Fetch public timeline and trending posts
- Full pagination support for large datasets
- Automatic deduplication of posts
- Proxy support with automatic rotation
- Handles pagination and large datasets automatically
- Exports to JSON, CSV, Excel, or connect via API

### How much will it cost?

| Results | Estimated Cost |
|---------|---------------|
| 100     | ~$0.01        |
| 1,000   | ~$0.05        |
| 10,000  | ~$0.25        |

| Cost Component | Per 1,000 Results |
|----------------|-------------------|
| Platform compute | ~$0.03 |
| Proxy (datacenter) | ~$0.02 |
| **Total** | **~$0.05** |

Mastodon has a public REST API, so scraping is very lightweight and cost-effective. No browser rendering is needed.

### How to use

1. Go to the Mastodon Scraper page on Apify Store
2. Click "Start" or "Try for free"
3. Enter Mastodon profile URLs (e.g., `https://mastodon.social/@Mastodon`) or search terms
4. Optionally change the target instance (default: mastodon.social)
5. Set the maximum number of items
6. Click "Start" and wait for the results

### Input parameters

| Parameter | Type | Description | Default |
|-----------|------|-------------|---------|
| startUrls | array | Mastodon profile URLs to scrape | - |
| searchTerms | array | Search queries for finding posts | - |
| instance | string | Default Mastodon instance for search/trending | mastodon.social |
| scrapePublicTimeline | boolean | Scrape the public timeline | false |
| scrapeTrending | boolean | Scrape trending posts | false |
| maxItems | number | Max posts to return | 100 |
| maxConcurrency | number | Parallel request limit | 10 |
| proxyConfig | object | Proxy settings | Apify Proxy |

### Output

The actor produces a dataset with the following fields:

```json
{
    "url": "https://mastodon.social/@Mastodon/123456789",
    "content": "Welcome to Mastodon! This is a decentralized social network.",
    "author": "Mastodon",
    "handle": "@Mastodon@mastodon.social",
    "instance": "mastodon.social",
    "favouritesCount": 42,
    "reblogsCount": 15,
    "repliesCount": 3,
    "createdAt": "2024-01-15T10:30:00.000Z",
    "mediaAttachments": ["https://media.mastodon.social/image.jpg"],
    "tags": ["mastodon", "fediverse"],
    "language": "en",
    "scrapedAt": "2024-01-16T08:00:00.000Z"
}
```

| Field | Type | Description |
|-------|------|-------------|
| url | string | Post URL |
| content | string | Post text content (HTML stripped) |
| author | string | Display name of the author |
| handle | string | Full handle (e.g., @user@instance) |
| instance | string | Mastodon instance domain |
| favouritesCount | number | Number of favourites/likes |
| reblogsCount | number | Number of reblogs/boosts |
| repliesCount | number | Number of replies |
| createdAt | string | Post creation timestamp (ISO 8601) |
| mediaAttachments | array | Media attachment URLs |
| tags | array | Hashtags used in the post |
| language | string | Post language code |
| scrapedAt | string | Scrape timestamp (ISO 8601) |

### Integrations

Connect Mastodon Scraper with other tools:

- **Apify API** -- REST API for programmatic access
- **Webhooks** -- get notified when a run finishes
- **Zapier / Make** -- connect to 5,000+ apps
- **Google Sheets** -- export directly to spreadsheets

#### API Example (Node.js)

```javascript
import { ApifyClient } from 'apify-client';
const client = new ApifyClient({ token: 'YOUR_TOKEN' });
const run = await client.actor('YOUR_USERNAME/mastodon-scraper').call({
    startUrls: [{ url: 'https://mastodon.social/@Mastodon' }],
    maxItems: 100,
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
```

#### API Example (Python)

```python
from apify_client import ApifyClient
client = ApifyClient('YOUR_TOKEN')
run = client.actor('YOUR_USERNAME/mastodon-scraper').call(run_input={
    'startUrls': [{'url': 'https://mastodon.social/@Mastodon'}],
    'maxItems': 100,
})
items = client.dataset(run['defaultDatasetId']).list_items().items
```

#### API Example (cURL)

```bash
curl "https://api.apify.com/v2/acts/YOUR_USERNAME~mastodon-scraper/runs" \
  -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -d '{"startUrls": [{"url": "https://mastodon.social/@Mastodon"}], "maxItems": 100}'
```

### Tips and tricks

- Start with a small `maxItems` (10-20) to test before running large scrapes
- You can scrape any Mastodon-compatible instance, not just mastodon.social
- Combine profile scraping with search terms to get comprehensive coverage
- The public timeline and trending endpoints give you a quick snapshot of activity on any instance
- No authentication or API keys are needed -- Mastodon's public API is open

### FAQ

**Q: Does this actor require login credentials?**
A: No. Mastodon has a public REST API that does not require authentication for reading public posts.

**Q: How fast is the scraping?**
A: Very fast. Since it uses the REST API directly, it can scrape 500-1,000+ posts per minute depending on the instance.

**Q: Can I scrape any Mastodon instance?**
A: Yes, any instance running Mastodon or a compatible server (Pleroma, Akkoma, etc.) that exposes the standard Mastodon API.

**Q: What should I do if I get rate limited?**
A: Lower the maxConcurrency setting and enable proxy rotation. Most Mastodon instances have generous rate limits (300 requests per 5 minutes).

**Q: Can I scrape private/followers-only posts?**
A: No. This actor only accesses publicly available posts through the public API.

### Is it legal to scrape Mastodon?

Web scraping of publicly available data is generally legal based on precedents like the LinkedIn v. HiQ Labs case. This actor only accesses publicly available data through Mastodon's official public REST API. Mastodon instances explicitly provide these API endpoints for public access. Always review and respect individual instance rules and Terms of Service. For more information, see [Apify's blog on web scraping legality](https://blog.apify.com/is-web-scraping-legal/).

### Limitations

- Only public posts are accessible (no private/followers-only content)
- Search functionality depends on the instance having search enabled
- Some smaller instances may have stricter rate limits
- Trending posts endpoint may not be available on all instances

### Changelog

- **v0.1** (2026-04-23) -- Initial release

# Actor input Schema

## `startUrls` (type: `array`):

Mastodon profile URLs to scrape posts from. Works with any Mastodon instance (e.g. mastodon.social, fosstodon.org).

## `searchTerms` (type: `array`):

Search queries to find posts across the specified instance.

## `instance` (type: `string`):

Default Mastodon instance for search and trending. Used when searchTerms are provided.

## `scrapePublicTimeline` (type: `boolean`):

Also scrape the public timeline of the specified instance.

## `scrapeTrending` (type: `boolean`):

Also scrape trending posts from the specified instance.

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

Maximum number of posts to scrape. Use 0 or leave empty for unlimited.

## `maxConcurrency` (type: `integer`):

Maximum number of requests processed in parallel.

## `debugMode` (type: `boolean`):

Enables verbose logging for troubleshooting.

## `extendOutputFunction` (type: `string`):

A JavaScript function to customize each output item. Receives { data, request }.

## `proxyConfig` (type: `object`):

Select proxies to be used.

## Actor input object example

```json
{
  "startUrls": [
    {
      "url": "https://mastodon.social/@Mastodon"
    }
  ],
  "searchTerms": [
    "open source"
  ],
  "instance": "mastodon.social",
  "scrapePublicTimeline": false,
  "scrapeTrending": false,
  "maxItems": 100,
  "maxConcurrency": 10,
  "debugMode": false,
  "extendOutputFunction": "async ({ data }) => {\n    return data;\n}",
  "proxyConfig": {
    "useApifyProxy": true
  }
}
```

# 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 = {
    "startUrls": [
        {
            "url": "https://mastodon.social/@Mastodon"
        }
    ],
    "searchTerms": [
        "open source"
    ],
    "instance": "mastodon.social",
    "extendOutputFunction": async ({ data }) => {
        return data;
    },
    "proxyConfig": {
        "useApifyProxy": true
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("glassventures/mastodon-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 = {
    "startUrls": [{ "url": "https://mastodon.social/@Mastodon" }],
    "searchTerms": ["open source"],
    "instance": "mastodon.social",
    "extendOutputFunction": """async ({ data }) => {
    return data;
}""",
    "proxyConfig": { "useApifyProxy": True },
}

# Run the Actor and wait for it to finish
run = client.actor("glassventures/mastodon-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 '{
  "startUrls": [
    {
      "url": "https://mastodon.social/@Mastodon"
    }
  ],
  "searchTerms": [
    "open source"
  ],
  "instance": "mastodon.social",
  "extendOutputFunction": "async ({ data }) => {\\n    return data;\\n}",
  "proxyConfig": {
    "useApifyProxy": true
  }
}' |
apify call glassventures/mastodon-scraper --silent --output-dataset

```

## MCP server setup

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