# Instagram Hashtag Username Scraper (`coderx/instagram-hashtag-username-scraper`) Actor

This actor scrapes Instagram posts based on a specified hashtag and extracts usernames, profile names, and user IDs. It helps track engaged users, analyze social media trends, and gather audience insights. Ideal for influencer research, marketing, and hashtag-based user analysis.

- **URL**: https://apify.com/coderx/instagram-hashtag-username-scraper.md
- **Developed by:** [CoderX](https://apify.com/coderx) (community)
- **Categories:** Automation, Lead generation, Social media
- **Stats:** 1,109 total users, 8 monthly users, 97.7% runs succeeded, 19 bookmarks
- **User rating**: 3.44 out of 5 stars

## Pricing

$0.18 / 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?

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

## Instagram Hashtag Scraper

### 📌 Overview

Instagram Hashtag Scraper is a powerful tool designed to extract usernames of users who have posted content under a specific hashtag. Simply input a hashtag, set the desired number of usernames, and let the scraper fetch relevant user data efficiently.

### 🚀 Features

- Extracts usernames from posts/reels associated with a given hashtag
- Supports batch scraping with custom limits
- Detects expired or invalid cookies for troubleshooting
- Optimized for performance and reliability
- Automatically scrolls through posts for deeper extraction

### 🔧 How It Works

1. Enter a hashtag of your choice.
2. Set the number of usernames you wish to retrieve.
3. The scraper processes the hashtag and fetches associated usernames.
4. Data is stored for easy access and analysis.
5. If no posts are found, it suggests checking cookies or the keyword.

### 📥 Input Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `hashtag` | `string` | The hashtag to scrape usernames from |
| `max_items` | `integer` | (Optional) The maximum number of usernames to retrieve |
| `cookies` | `string` |  Instagram session cookies for authentication |

### 📤 Output Data

The scraper returns structured JSON data containing:

- `search_keyword` – The input hashtag
- `caption` – Extracted hashtags from captions
- `user_pk` – Unique user ID
- `username` – Instagram handle
- `id` – Post ID
- `code` – Unique post code

Each extracted entry includes:

- **search\_keyword** - The searched hashtag.
- **caption** - Extracted hashtags from the post.
- **user\_pk** - The unique user ID.
- **username** - The Instagram username.
- **id** - The post ID.
- **code** - The unique Instagram post code.

## 🔑 How to Get Instagram Cookies

To run the scraper, you need to extract your Instagram session cookies. Follow these steps:

1. Install the **[Export Cookie JSON file for Puppeteer](https://chromewebstore.google.com/detail/export-cookie-json-file-f/nmckokihipjgplolmcmjakknndddifde)** extension in your browser.
2. Log in to Instagram using your account.
3. Click on the extension icon and export your cookies as a JSON file.
4. Copy the contents of the file and provide them as input to the scraper.

### 📌 SEO Optimized Keywords

- Instagram Hashtag Scraper
- Extract Instagram Usernames
- Hashtag Data Mining
- Social Media Scraping
- Instagram Marketing Tool
- Web Scraping for Instagram

🚀 **Start scraping Instagram hashtags today!**

***

#### 🔗 Stay Updated

Follow the latest updates and improvements by ⭐ starring this repository!

# Actor input Schema

## `keyword` (type: `string`):

Hashtag to search for on Instagram (e.g., nature).

## `Max_items` (type: `integer`):

No. of posts to scrape

## `cookies` (type: `array`):

Enter cookie of your account

## Actor input object example

```json
{
  "keyword": "nature",
  "Max_items": 1000,
  "cookies": [
    {
      "name": "datr",
      "value": "sL_rZ1VMWqwRVcCuWXiAQmZX",
      "domain": ".instagram.com",
      "path": "/",
      "expires": 1778063286.150982,
      "httpOnly": true,
      "secure": true
    },
    {
      "name": "ig_did",
      "value": "1C8AA31D-EA64-4F7A-BFB7-A5E4CFB044A2",
      "domain": ".instagram.com",
      "path": "/",
      "expires": 1775039289.586829,
      "httpOnly": true,
      "secure": true
    },
    {
      "name": "mid",
      "value": "Z-u_sAALAAFLVNABqbKzftY5QmVX",
      "domain": ".instagram.com",
      "path": "/",
      "expires": 1778063286.151132,
      "httpOnly": true,
      "secure": true
    },
    {
      "name": "csrftoken",
      "value": "K2icskn2peDTQSn8Fpc4d0UeXI5gvHUA",
      "domain": ".instagram.com",
      "path": "/",
      "expires": 1774971325.552493,
      "httpOnly": false,
      "secure": true
    },
    {
      "name": "ds_user_id",
      "value": "73139193689",
      "domain": ".instagram.com",
      "path": "/",
      "expires": 1751297725.552724,
      "httpOnly": false,
      "secure": true
    },
    {
      "name": "sessionid",
      "value": "73539491489%3A377qgGLgpVU9QO%3A18%3AAYdYA1n9adejJUjkr8k17j3-LCTLoeEC2wsBnd-_oA",
      "domain": ".instagram.com",
      "path": "/",
      "expires": 1775039435.486017,
      "httpOnly": true,
      "secure": true
    },
    {
      "name": "wd",
      "value": "1358x642",
      "domain": ".instagram.com",
      "path": "/",
      "expires": 1744126523,
      "httpOnly": false,
      "secure": true,
      "sameSite": "Lax"
    },
    {
      "name": "rur",
      "value": "\"RVA\\05473539498689\\0541775057726:01f7831497b9bd63ed547dedca6805d32284ae9700d432ff00bfdd136ae1c88416ec2841\"",
      "domain": ".instagram.com",
      "path": "/",
      "expires": -1,
      "httpOnly": true,
      "secure": true,
      "sameSite": "Lax"
    }
  ]
}
```

# 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 = {
    "keyword": "nature",
    "Max_items": 1000,
    "cookies": [
        {
            "name": "datr",
            "value": "sL_rZ1VMWqwRVcCuWXiAQmZX",
            "domain": ".instagram.com",
            "path": "/",
            "expires": 1778063286.150982,
            "httpOnly": true,
            "secure": true
        },
        {
            "name": "ig_did",
            "value": "1C8AA31D-EA64-4F7A-BFB7-A5E4CFB044A2",
            "domain": ".instagram.com",
            "path": "/",
            "expires": 1775039289.586829,
            "httpOnly": true,
            "secure": true
        },
        {
            "name": "mid",
            "value": "Z-u_sAALAAFLVNABqbKzftY5QmVX",
            "domain": ".instagram.com",
            "path": "/",
            "expires": 1778063286.151132,
            "httpOnly": true,
            "secure": true
        },
        {
            "name": "csrftoken",
            "value": "K2icskn2peDTQSn8Fpc4d0UeXI5gvHUA",
            "domain": ".instagram.com",
            "path": "/",
            "expires": 1774971325.552493,
            "httpOnly": false,
            "secure": true
        },
        {
            "name": "ds_user_id",
            "value": "73139193689",
            "domain": ".instagram.com",
            "path": "/",
            "expires": 1751297725.552724,
            "httpOnly": false,
            "secure": true
        },
        {
            "name": "sessionid",
            "value": "73539491489%3A377qgGLgpVU9QO%3A18%3AAYdYA1n9adejJUjkr8k17j3-LCTLoeEC2wsBnd-_oA",
            "domain": ".instagram.com",
            "path": "/",
            "expires": 1775039435.486017,
            "httpOnly": true,
            "secure": true
        },
        {
            "name": "wd",
            "value": "1358x642",
            "domain": ".instagram.com",
            "path": "/",
            "expires": 1744126523,
            "httpOnly": false,
            "secure": true,
            "sameSite": "Lax"
        },
        {
            "name": "rur",
            "value": "\"RVA\\05473539498689\\0541775057726:01f7831497b9bd63ed547dedca6805d32284ae9700d432ff00bfdd136ae1c88416ec2841\"",
            "domain": ".instagram.com",
            "path": "/",
            "expires": -1,
            "httpOnly": true,
            "secure": true,
            "sameSite": "Lax"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("coderx/instagram-hashtag-username-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 = {
    "keyword": "nature",
    "Max_items": 1000,
    "cookies": [
        {
            "name": "datr",
            "value": "sL_rZ1VMWqwRVcCuWXiAQmZX",
            "domain": ".instagram.com",
            "path": "/",
            "expires": 1778063286.150982,
            "httpOnly": True,
            "secure": True,
        },
        {
            "name": "ig_did",
            "value": "1C8AA31D-EA64-4F7A-BFB7-A5E4CFB044A2",
            "domain": ".instagram.com",
            "path": "/",
            "expires": 1775039289.586829,
            "httpOnly": True,
            "secure": True,
        },
        {
            "name": "mid",
            "value": "Z-u_sAALAAFLVNABqbKzftY5QmVX",
            "domain": ".instagram.com",
            "path": "/",
            "expires": 1778063286.151132,
            "httpOnly": True,
            "secure": True,
        },
        {
            "name": "csrftoken",
            "value": "K2icskn2peDTQSn8Fpc4d0UeXI5gvHUA",
            "domain": ".instagram.com",
            "path": "/",
            "expires": 1774971325.552493,
            "httpOnly": False,
            "secure": True,
        },
        {
            "name": "ds_user_id",
            "value": "73139193689",
            "domain": ".instagram.com",
            "path": "/",
            "expires": 1751297725.552724,
            "httpOnly": False,
            "secure": True,
        },
        {
            "name": "sessionid",
            "value": "73539491489%3A377qgGLgpVU9QO%3A18%3AAYdYA1n9adejJUjkr8k17j3-LCTLoeEC2wsBnd-_oA",
            "domain": ".instagram.com",
            "path": "/",
            "expires": 1775039435.486017,
            "httpOnly": True,
            "secure": True,
        },
        {
            "name": "wd",
            "value": "1358x642",
            "domain": ".instagram.com",
            "path": "/",
            "expires": 1744126523,
            "httpOnly": False,
            "secure": True,
            "sameSite": "Lax",
        },
        {
            "name": "rur",
            "value": "\"RVA\\05473539498689\\0541775057726:01f7831497b9bd63ed547dedca6805d32284ae9700d432ff00bfdd136ae1c88416ec2841\"",
            "domain": ".instagram.com",
            "path": "/",
            "expires": -1,
            "httpOnly": True,
            "secure": True,
            "sameSite": "Lax",
        },
    ],
}

# Run the Actor and wait for it to finish
run = client.actor("coderx/instagram-hashtag-username-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 '{
  "keyword": "nature",
  "Max_items": 1000,
  "cookies": [
    {
      "name": "datr",
      "value": "sL_rZ1VMWqwRVcCuWXiAQmZX",
      "domain": ".instagram.com",
      "path": "/",
      "expires": 1778063286.150982,
      "httpOnly": true,
      "secure": true
    },
    {
      "name": "ig_did",
      "value": "1C8AA31D-EA64-4F7A-BFB7-A5E4CFB044A2",
      "domain": ".instagram.com",
      "path": "/",
      "expires": 1775039289.586829,
      "httpOnly": true,
      "secure": true
    },
    {
      "name": "mid",
      "value": "Z-u_sAALAAFLVNABqbKzftY5QmVX",
      "domain": ".instagram.com",
      "path": "/",
      "expires": 1778063286.151132,
      "httpOnly": true,
      "secure": true
    },
    {
      "name": "csrftoken",
      "value": "K2icskn2peDTQSn8Fpc4d0UeXI5gvHUA",
      "domain": ".instagram.com",
      "path": "/",
      "expires": 1774971325.552493,
      "httpOnly": false,
      "secure": true
    },
    {
      "name": "ds_user_id",
      "value": "73139193689",
      "domain": ".instagram.com",
      "path": "/",
      "expires": 1751297725.552724,
      "httpOnly": false,
      "secure": true
    },
    {
      "name": "sessionid",
      "value": "73539491489%3A377qgGLgpVU9QO%3A18%3AAYdYA1n9adejJUjkr8k17j3-LCTLoeEC2wsBnd-_oA",
      "domain": ".instagram.com",
      "path": "/",
      "expires": 1775039435.486017,
      "httpOnly": true,
      "secure": true
    },
    {
      "name": "wd",
      "value": "1358x642",
      "domain": ".instagram.com",
      "path": "/",
      "expires": 1744126523,
      "httpOnly": false,
      "secure": true,
      "sameSite": "Lax"
    },
    {
      "name": "rur",
      "value": "\\"RVA\\\\05473539498689\\\\0541775057726:01f7831497b9bd63ed547dedca6805d32284ae9700d432ff00bfdd136ae1c88416ec2841\\"",
      "domain": ".instagram.com",
      "path": "/",
      "expires": -1,
      "httpOnly": true,
      "secure": true,
      "sameSite": "Lax"
    }
  ]
}' |
apify call coderx/instagram-hashtag-username-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,coderx/instagram-hashtag-username-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/BQypXe5Ph2UPmGHy5/builds/lUJuaBJYYxNMnGRb4/openapi.json
