# Mastodon Explorer (`jupri/mastodon-scraper`) Actor

🐘 Scrape Mastodon Social Network websites

- **URL**: https://apify.com/jupri/mastodon-scraper.md
- **Developed by:** [cat](https://apify.com/jupri) (community)
- **Categories:** Social media
- **Features:** Full permissions
- **Stats:** 33 total users, 0 monthly users, 100.0% runs succeeded, 4 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

## Welcome to Mastodon Scraper

![don't be sad readme is here](https://raw.githubusercontent.com/JupriGH/resources/main/cats/catframe.png)

### 🐘 About Mastodon (social network)

<img width="128" src="https://upload.wikimedia.org/wikipedia/commons/d/d5/Mastodon_logotype_%28simple%29_new_hue.svg">

**Mastodon** is [free and open-source software](https://en.wikipedia.org/wiki/Free_and_open-source_software "Free and open-source software") for running [self-hosted](https://en.wikipedia.org/wiki/Self-hosting_\(web_services\) "Self-hosting (web services)")  [social networking services](https://en.wikipedia.org/wiki/Social_networking_service "Social networking service"). It has [microblogging](https://en.wikipedia.org/wiki/Microblogging "Microblogging") features similar to [Twitter](https://en.wikipedia.org/wiki/Twitter "Twitter"), which are offered by a large number of independently run [nodes](https://en.wikipedia.org/wiki/Node_\(networking\) "Node (networking)"), known as [instances](https://en.wikipedia.org/wiki/Instance_\(computer_science\) "Instance (computer science)"), each with its own [code of conduct](https://en.wikipedia.org/wiki/Code_of_conduct "Code of conduct"), [terms of service](https://en.wikipedia.org/wiki/Terms_of_service "Terms of service"), [privacy policy](https://en.wikipedia.org/wiki/Privacy_policy "Privacy policy"), privacy options, and [content moderation](https://en.wikipedia.org/wiki/Content_moderation "Content moderation") policies.[\[6\]](https://en.wikipedia.org/wiki/Mastodon_\(social_network\)#cite_note-Chan_2022-6)[\[7\]](https://en.wikipedia.org/wiki/Mastodon_\(social_network\)#cite_note-:1-7)[\[8\]](https://en.wikipedia.org/wiki/Mastodon_\(social_network\)#cite_note-8)

### 🐘 About This Actor

Scrape data from Mastadon, the decentralized alternative to Twitter. Extract information on users, their "toots," likes, and favorites or scrape data based on a search query, such as a hashtag or a keyword. Export accumulated data into a variety of database formats.

<img width="240" src="https://www.healthprochiro.com/wp-content/uploads/2022/09/under-const.jpg">

### 🐘 Tutorial

#### 📁 Parameters

| Input| Type |  Description |
|-|-|-|
| `query` | ***string array*** | List of `Query`, `Search Terms` or `Start URL` |
| `portal` | ***string*** | Default portal *`(default: mastodon.social)`* |
| `limit` | ***integer*** | Number of results *`(per-query)`* |

#### 📁 Basic Usage

```yaml
## search posts
{ "query": ["sponge bobs"], "limit": 10 } 
```

```yaml
## search hashtag
{ "query": ["#python"], "limit": 10 } 
```

```yaml
## just paste an url
{ "query": ["https://mastodon.social/@elonmusk"], "limit": 10 } 
```

#### 📁 Advanced Usage

***Mastodon Query Language (MQL)***

```html
[ [ <COMMAND:> | # | @ ] [ <NAME> | <ID> | <KEYWORD> ] [ / <SECTION> ] | <URL> ] 
```

***Possible QUERY  values***

| Format | Example | Description |
|-|-|-|
| **KEYWORDS** | `search terms` |***Search Anything***|
| `KEYWORDS` |`webscraping`| Search posts |
| `users:KEYWORDS` |`users:python`| Search users |
| `hashtags:KEYWORDS` |`hashtags:php`| Search hashtags |
| **portal:SECTION** | | ***Explore Current Portal***|
| `portal:about` | | Portal info & description |
| `portal:info` | | Portal info |
| `portal:description` | | Portal description |
| `portal:posts` | | Portal posts |
| `portal:hashtags` | | Portal hashtags |
| `portal:news` | | Portal news |
| `portal:feeds` | | All feeds |
| `portal:local` | | Portal feeds (local) |
| `portal:remote` | | Portal feeds (remote) |
| **#HASHTAG** | `#python` | ***Scrape Hashtag***
| `/info` | `#python/info` | Hashtag info |
| `/posts` | `#python/posts` | Hashtag posts |
| **@USER\[@SERVER]** | `@elonmusk` | ***Scraper User*** |
| | `@elonmusk@mastodon.social` | |
| `/info` | `@Gargron/info` | User info |
| `/posts` | `@Gargron/posts` | User posts |
| `/replies` | `@Gargron/replies` | User posts (with replies) |
| `/media` | `@Gargron/media` | User media |
| `/following` | `@Gargron/following` | User following |
| `/followers` | `@Gargron/followers` | User followers |
| **\<POST_ID>** | `112718231305707672` | ***Scraper a Post*** |
|`/info` | `112718231305707672/info` |Post content |
|`/comments` | `112718231305707672/comments` | Post comments |
|`/reblogs` | `112718231305707672/reblogs` | Post reblogs (boosts) |
|`/likes` | `112718231305707672/likes` | Post liked users (favourites) |
| **https:\<PORTAL_URL>** | `https://mastodon.social` | ***Start URL***
| | `https://mastodon.social/@elonmusk` |

#### 📁 Examples

By default the actor will scrape from `mastodon.social` portal (eg: https://mastodon.social)

***Example 1: Portal***

To scrape from other portal, use `portal` parameter and specify the website/portal hostname :

```yaml
{ "portal": "fosstodon.org" }
```

***Example 2: Scraping #hastag***

```yaml
{ "query": "#microsoft" }
```

***Example 3: Scraping user posts***

```yaml
{ "query": "@username" }
{ "query": "@username@portal" }
```

***Example 4: Using URL as input***

When you specify URL for `query` parameter, it will automatically parsed with appropriate parameter :

```yaml
{ "query": "https://fosstodon.org/@Joefree/media" }
```

***Example 5: Number of results***

Use `limit` parameter to get more results.

```yaml
{ "query": "microsoft", "limit": 100 }
```

### 🐘  Output Examples

```yaml
{
    "account": {
        "acct": "Gargron",
        "avatar": "https://files.mastodon.social/accounts/avatars/000/000/001/original/dc4286ceb8fab734.jpg",
        "avatar_static": "https://files.mastodon.social/accounts/avatars/000/000/001/original/dc4286ceb8fab734.jpg",
        "created_at": "2016-03-16T00:00:00.000Z",
        "discoverable": true,
        "display_name": "Eugen Rochko",
        "fields": [
            {
                "name": "Patreon",
                "value": "<a href=\"https://www.patreon.com/mastodon\" target=\"_blank\" rel=\"nofollow noopener noreferrer me\"><span class=\"invisible\">https://www.</span><span class=\"\">patreon.com/mastodon</span><span class=\"invisible\"></span></a>"
            },
            {
                "name": "GitHub",
                "value": "<a href=\"https://github.com/Gargron\" target=\"_blank\" rel=\"nofollow noopener noreferrer me\"><span class=\"invisible\">https://</span><span class=\"\">github.com/Gargron</span><span class=\"invisible\"></span></a>",
                "verified_at": "2023-02-07T23:24:40.347+00:00"
            }
        ],
        "followers_count": 312471,
        "following_count": 395,
        "header": "https://files.mastodon.social/accounts/headers/000/000/001/original/3b91c9965d00888b.jpeg",
        "header_static": "https://files.mastodon.social/accounts/headers/000/000/001/original/3b91c9965d00888b.jpeg",
        "id": "1",
        "last_status_at": "2023-04-28",
        "note": "<p>Founder, CEO and lead developer <span class=\"h-card\"><a href=\"https://mastodon.social/@Mastodon\" class=\"u-url mention\">@<span>Mastodon</span></a></span>, Germany.</p>",
        "statuses_count": 73541,
        "url": "https://mastodon.social/@Gargron",
        "username": "Gargron"
    },
    "application": {
        "name": "Web"
    },
    "card": {
        "blurhash": "U34x7la*9EoYxNfQayfR4mj:?cWIajfRj[a{",
        "description": "Learn how to get verified on Mastodon",
        "height": 267,
        "image": "https://files.mastodon.social/cache/preview_cards/images/059/998/839/original/74e91efacf98def0.png",
        "title": "Verification",
        "type": "link",
        "url": "https://joinmastodon.org/verification",
        "width": 400
    },
    "content": "<p>Looks like <span class=\"h-card\"><a href=\"https://mastodon.social/@arstechnica\" class=\"u-url mention\">@<span>arstechnica</span></a></span> is now verified on here! Always great to see this feature used. It'll be even more prominent in the future.</p><p><a href=\"https://joinmastodon.org/verification\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><span class=\"invisible\">https://</span><span class=\"\">joinmastodon.org/verification</span><span class=\"invisible\"></span></a></p>",
    "created_at": "2023-04-27T22:37:39.080Z",
    "favourites_count": 420,
    "id": "110273171231251728",
    "language": "en",
    "mentions": [
        {
            "acct": "arstechnica",
            "id": "110266162634306901",
            "url": "https://mastodon.social/@arstechnica",
            "username": "arstechnica"
        }
    ],
    "reblogs_count": 280,
    "replies_count": 14,
    "uri": "https://mastodon.social/users/Gargron/statuses/110273171231251728",
    "url": "https://mastodon.social/@Gargron/110273171231251728",
    "visibility": "public"
}
```

### 🐘 Support

<img width="240" src="https://upload.wikimedia.org/wikipedia/commons/d/dd/Mastodon_mascot_vector_version.svg">

# Actor input Schema

## `query` (type: `array`):

💡 <b><code>#hastag</code></b> or <b><code>@username</code></b> or <b><code>URL</code></b><br><br>URL examples :<i><br><code>https://\[portal]/@username</code><br><code>https://\[portal]/tags/\[hashtag]</code></i>

## `portal` (type: `string`):

💡 Portal Hostname <i>(default: mastadon.social)</i>

## `limit` (type: `integer`):

💡 Number of results <i><code>(per-query)</code></i>

## `dev_proxy_config` (type: `object`):

💡 <b>Supported protocol:</b><br><br><b>HTTP(S), SOCKS5</b><br><code>{http|socks5}://{user:pass}@{hostname|ip-address}:port</code><br><br><b>Example</b>: <code>socks5://example.com:9000</code>

## `dev_custom_headers` (type: `array`):

💡 Additional HTTP Headers

## `dev_custom_cookies` (type: `array`):

💡 Additional HTTP Cookies

## `dev_transform_fields` (type: `array`):

💡 <b>Transform the resulting output. Select only needed fields.</b><br><br>For nested object use <b>DOT</b>. For example: <pre>address.streetAddress</pre><br>For nested array use <b>NUMBER</b> <i>(index of array element starting from index=0)</i>. For example: <pre>images.0.url</pre>

## `dev_dataset_name` (type: `string`):

💡 <b>Save results into custom named Dataset, use mask to customize dataset name</b><br><br><code>{ACTOR} = actor name<br>{DATE} = date (YYYYMMDD)<br>{TIME} = time (HHMMSS)</code><br><br>This masks can be used to autogenerate Dataset Name.<br><br>example: <i><code>data-{DATE}</code></i><br>Depending on today date the dataset name will be: <code>data-20230603</code><i><br><br>default: <code>data-{ACTOR}-{DATE}-{TIME}</code></i>

## `dev_dataset_clear` (type: `boolean`):

Clear Dataset before insert/update.

## `dev_no_strip` (type: `boolean`):

💡 Keep/Save empty values <i><code>(NULL, FALSE, empty ARRAY, empty OBJECT, empty STRING)</code></i>

## Actor input object example

```json
{
  "query": [
    "@Mastodon/info",
    "@Mastodon",
    "#python",
    "drama",
    "https://mastodon.social/public/local"
  ],
  "limit": 5,
  "dev_custom_cookies": [
    {
      "key": "_session_id",
      "value": ""
    }
  ]
}
```

# 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 = {
    "query": [
        "@Mastodon/info",
        "@Mastodon",
        "#python",
        "drama",
        "https://mastodon.social/public/local"
    ],
    "limit": 5,
    "dev_custom_cookies": [
        {
            "key": "_session_id",
            "value": ""
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("jupri/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 = {
    "query": [
        "@Mastodon/info",
        "@Mastodon",
        "#python",
        "drama",
        "https://mastodon.social/public/local",
    ],
    "limit": 5,
    "dev_custom_cookies": [{
            "key": "_session_id",
            "value": "",
        }],
}

# Run the Actor and wait for it to finish
run = client.actor("jupri/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 '{
  "query": [
    "@Mastodon/info",
    "@Mastodon",
    "#python",
    "drama",
    "https://mastodon.social/public/local"
  ],
  "limit": 5,
  "dev_custom_cookies": [
    {
      "key": "_session_id",
      "value": ""
    }
  ]
}' |
apify call jupri/mastodon-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,jupri/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/5Sorvh7sfx1hBpdVm/builds/6ZeGF871YmJF0sr1U/openapi.json
