# 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, 2 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 web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — 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

Download the OpenAPI definition: https://api.apify.com/v2/actors/F6S3V675or7aZ3pvx/builds/turWSkKihCIlkivOp/openapi.json
