# Threads Scraper — Keyword Search, Posts & Profiles (No Login) (`aydar_cosmos/threads-scraper`) Actor

Scrape public Meta Threads data without login: search posts by keyword or hashtag (the official API can't), plus public profiles and user posts. Returns clean, LLM-ready JSON — ideal for brand monitoring, social listening and AI agents. Reliable residential-proxy scraping.

- **URL**: https://apify.com/aydar\_cosmos/threads-scraper.md
- **Developed by:** [Aidar Gumerov](https://apify.com/aydar_cosmos) (community)
- **Categories:** Social media
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.00 / 1,000 results

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## Threads Scraper — Keyword Search, Posts & Profiles (No Login)

[![CI](https://github.com/aigumer/threads-scraper/actions/workflows/ci.yml/badge.svg)](https://github.com/aigumer/threads-scraper/actions/workflows/ci.yml)

Scrape public **Meta Threads** data at scale: **search posts by keyword or hashtag**, pull public **profiles**, and fetch a user's **posts** — returned as clean, **LLM-ready JSON**. No login, public data only.

> **Why this exists:** the official Threads API has **no keyword search and no streaming** — you cannot monitor a topic, brand, or hashtag through it. This scraper closes that gap. Keyword/hashtag search is the flagship capability.

---

### Features

- 🔎 **Keyword & hashtag search** — the thing the official API can't do.
- 👤 **Public profiles** — bio, links, follower count, verification, recent posts.
- 🧵 **User posts** — a specific public account's posts, with scroll pagination.
- 🤖 **LLM-ready output** — flat, predictable JSON that an AI agent can consume directly. Also exportable as CSV / Excel / JSON via the Apify dataset.
- 🛡️ **Reliable by design** — Camoufox anti-fingerprint browser, residential proxy, retries with exponential backoff, and a GraphQL-response capture strategy (not brittle DOM scraping).
- 🔒 **Privacy-first** — logged-out public data only, nothing persisted beyond the request.

### Modes

| `mode` | What you get | Required input |
|--------|--------------|----------------|
| `search` *(default)* | Public posts matching a keyword / `#hashtag` | `query` |
| `profile` | One public profile + its recent posts | `username` |
| `posts` | A specific user's public posts | `username` |

### Quick start

Runs out of the box — **no configuration needed**. The default run searches Threads for `openai` and returns 25 posts.

#### Input

```json
{
  "mode": "search",
  "query": "openai",
  "maxResults": 25,
  "proxyConfiguration": { "useApifyProxy": true, "apifyProxyGroups": ["RESIDENTIAL"] }
}
````

Profile example:

```json
{ "mode": "profile", "username": "natgeo", "maxResults": 10 }
```

#### Output (real example, `mode: search`)

```json
{
  "id": "3939159366922654199",
  "code": "DaqtJLbE9H3",
  "url": "https://www.threads.com/@technewsonweb/post/DaqtJLbE9H3",
  "text": "OpenAI Bio Bug Bounty.\nTesting for universal jailbreaks for biorisks.",
  "published_at": "2026-07-11T21:13:31+00:00",
  "like_count": 0,
  "reply_count": 0,
  "repost_count": 0,
  "quote_count": 0,
  "author": {
    "username": "technewsonweb",
    "user_pk": "63104067007",
    "is_verified": false,
    "profile_pic_url": "https://.../profile.jpg"
  },
  "media": [],
  "has_audio": false,
  "is_reply": false,
  "scraped_at": "2026-07-12T00:00:00+00:00"
}
```

Profile output (`mode: profile`) adds `full_name`, `biography`, `bio_links`, `follower_count`, `is_verified`, `is_private`, and a `posts[]` array of the above shape.

### Pricing (pay-per-event)

Single, simple per-result price — you only pay for items actually returned:

| Event | Price |
|-------|-------|
| Per result returned (any mode) | **$0.002** |

≈ **$2 per 1,000 results**. In `search` / `posts` each post is one result; in `profile` the profile (with its bundled recent posts) is one result. Charged automatically via Apify's `apify-default-dataset-item` event, and the SDK enforces your max-charge budget.

### Legal & privacy

- Scrapes **only logged-out, publicly visible** data — no login, no authentication, no private endpoints replayed.
- Aligned with the *Meta v. Bright Data (2024)* precedent on public data.
- No personal data is stored or logged beyond the lifetime of a single request (GDPR hygiene). You are responsible for how you use the output.

***

### Repository architecture

One codebase, three delivery channels:

```
core/       Pure scraping logic (search/profile/posts) → structured objects.
            Knows nothing about Apify or HTTP. Fully unit-tested.
src/        Apify Actor entrypoint — thin wrapper over core/ (input, billing).
.actor/     Apify config: actor.json, input_schema.json, dataset_schema.json,
            Dockerfile. (Pricing is set in the Apify Console — see DEPLOY.md.)
server/     FastAPI HTTP API + MCP server (thin adapter over the Apify Actor,
            deployed to Render — no browser, free-tier friendly).
tests/      Hermetic extractor tests + a manual live smoke check.
```

**Why Camoufox over stock Playwright?** Threads fingerprints the browser even when logged out. Camoufox is a hardened Firefox with anti-fingerprinting built in and a Playwright-compatible API — fewer blocks, no brittle stealth patches. The code falls back to stock Playwright Firefox when Camoufox isn't installed, so it stays importable and testable anywhere.

**How extraction works.** Threads is a React/Relay app; logged-out profile/post data is **not** in the initial HTML — it arrives via GraphQL/XHR after hydration. The browser layer captures those JSON responses and the extractor walks them for `thread_items` / `user` objects. This is far more robust than DOM scraping.

### Local development

```bash
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt          # core + actor
playwright install firefox               # or: python -m camoufox fetch

## Run unit tests (no network):
pip install pytest pytest-asyncio && pytest -q

## Live smoke test (hits real Threads):
python -m tests.live_check
```

Use `core` directly:

```python
import asyncio
from core import search, profile

posts = asyncio.run(search("#ai", limit=20))
natgeo = asyncio.run(profile("natgeo", post_limit=10))
```

### HTTP API + MCP server (thin adapter)

The server is a **thin adapter** over the Apify Actor — it doesn't run a browser,
so it fits a Render free instance. Set `APIFY_TOKEN` and it forwards to the Actor.

```bash
pip install -r server/requirements.txt
export APIFY_TOKEN=apify_api_...        # required
uvicorn server.app:app --reload
```

- `POST /search`  `{ "query": "openai", "limit": 25 }`
- `POST /profile` `{ "username": "natgeo", "limit": 10 }`
- `POST /posts`   `{ "username": "natgeo", "limit": 25 }`
- `GET  /health`  — liveness / keepalive
- `POST /mcp` — MCP server exposing `threads_search`, `threads_profile`, `threads_posts` for AI agents (see [MCP.md](MCP.md)).

Optional x402 payment gating is available behind `X402_ENABLED` (off by default).

### Deployment

- **Apify Actor** — built from this Git repo (see [`DEPLOY.md`](DEPLOY.md)).
- **Render** — HTTP + MCP server via [`render.yaml`](render.yaml) Blueprint, with a keepalive cron for the free tier.

### License

MIT

# Actor input Schema

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

What to scrape. 'search' finds posts by keyword/hashtag (flagship). 'profile' returns one public profile + recent posts. 'posts' returns a user's posts.

## `query` (type: `string`):

Keyword, phrase, or #hashtag to search public Threads posts for.

## `username` (type: `string`):

Public Threads handle, with or without the leading @.

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

Maximum posts to return (1–1000). For 'profile' this caps the recent posts included.

## `proxyConfiguration` (type: `object`):

Proxy used for scraping. Residential Apify Proxy is strongly recommended and used by default.

## Actor input object example

```json
{
  "mode": "search",
  "query": "#ai",
  "username": "natgeo",
  "maxResults": 25,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  }
}
```

# 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 = {
    "username": "natgeo"
};

// Run the Actor and wait for it to finish
const run = await client.actor("aydar_cosmos/threads-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 = { "username": "natgeo" }

# Run the Actor and wait for it to finish
run = client.actor("aydar_cosmos/threads-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "username": "natgeo"
}' |
apify call aydar_cosmos/threads-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=aydar_cosmos/threads-scraper",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Threads Scraper — Keyword Search, Posts & Profiles (No Login)",
        "description": "Scrape public Meta Threads data without login: search posts by keyword or hashtag (the official API can't), plus public profiles and user posts. Returns clean, LLM-ready JSON — ideal for brand monitoring, social listening and AI agents. Reliable residential-proxy scraping.",
        "version": "0.0",
        "x-build-id": "BMzThHR4iBJmzHAgk"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/aydar_cosmos~threads-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-aydar_cosmos-threads-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/aydar_cosmos~threads-scraper/runs": {
            "post": {
                "operationId": "runs-sync-aydar_cosmos-threads-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/aydar_cosmos~threads-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-aydar_cosmos-threads-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "mode"
                ],
                "properties": {
                    "mode": {
                        "title": "Mode",
                        "enum": [
                            "search",
                            "profile",
                            "posts"
                        ],
                        "type": "string",
                        "description": "What to scrape. 'search' finds posts by keyword/hashtag (flagship). 'profile' returns one public profile + recent posts. 'posts' returns a user's posts.",
                        "default": "search"
                    },
                    "query": {
                        "title": "Search query (mode = search)",
                        "type": "string",
                        "description": "Keyword, phrase, or #hashtag to search public Threads posts for.",
                        "default": "openai"
                    },
                    "username": {
                        "title": "Username (mode = profile / posts)",
                        "type": "string",
                        "description": "Public Threads handle, with or without the leading @."
                    },
                    "maxResults": {
                        "title": "Max results",
                        "minimum": 1,
                        "maximum": 1000,
                        "type": "integer",
                        "description": "Maximum posts to return (1–1000). For 'profile' this caps the recent posts included.",
                        "default": 25
                    },
                    "proxyConfiguration": {
                        "title": "Proxy",
                        "type": "object",
                        "description": "Proxy used for scraping. Residential Apify Proxy is strongly recommended and used by default.",
                        "default": {
                            "useApifyProxy": true,
                            "apifyProxyGroups": [
                                "RESIDENTIAL"
                            ]
                        }
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
