# Instagram Tagged Posts Scraper (`crawlerbros/instagram-tagged-posts-scraper`) Actor

Extracts posts where a specific Instagram user is tagged by others. Returns complete post data including likes, comments, captions, media URLs, and author details with profile pictures and verification status.

- **URL**: https://apify.com/crawlerbros/instagram-tagged-posts-scraper.md
- **Developed by:** [Crawler Bros](https://apify.com/crawlerbros) (community)
- **Categories:** Social media, Other, Automation
- **Stats:** 32 total users, 3 monthly users, 94.7% runs succeeded, 0 bookmarks
- **User rating**: 5.00 out of 5 stars

## Pricing

from $5.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.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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

## Instagram Tagged Posts Scraper

Extract posts where a user is tagged on Instagram. This scraper navigates to the "Tagged" tab of any Instagram profile and extracts all posts where the target user has been tagged by others. Accepts one or more usernames per run - each username's post URLs are found by the browser, then handed off to run in the background while the browser moves on to the next username.

### Features

- 🏷️ **Tagged Posts Extraction**: Scrapes posts from the `/tagged/` tab of any Instagram profile
- 👥 **Multiple Usernames**: Process several usernames in a single run, pipelined so scraping overlaps with crawling
- 📊 **Engagement Metrics**: Extracts likes, comments, and views for each post
- 📸 **Media URLs**: Collects image and video URLs from posts
- 👤 **Author Information**: Gets details about who posted/tagged the user
- 🔐 **Cookie Authentication**: Supports MongoDB cookie rotation and file-based cookies
- 🛡️ **Anti-Detection**: Human behavior simulation, stealth scripts, and random delays
- 📧 **Email Alerts**: Automatic notifications when cookies fail or are exhausted

### Input Parameters

| Parameter                 | Type          | Required | Default           | Description                                              |
| ------------------------- | ------------- | -------- | ----------------- | --------------------------------------------------------- |
| `usernames`               | Array\[String] | Yes      | -                 | One or more Instagram usernames whose tagged posts to scrape |
| `maxPosts`                | Integer       | No       | 100               | Maximum number of tagged posts to extract per username     |
| `cookies`                 | String        | No       | -                 | Instagram cookies in JSON format                           |
| `sessionName`             | String        | No       | "default\_session" | Session name for cookie persistence                       |

### Example Input

```json
{
  "usernames": ["instagram", "natgeo"],
  "maxPosts": 20
}
```

### Output Format

Each tagged post is returned with the following structure:

```json
{
  "tagged_username": "instagram",
  "post_url": "https://www.instagram.com/p/ABC123/",
  "description": "Post caption here...",
  "post_type": "image",
  "like_count": 12345,
  "comment_count": 234,
  "view_count": 0,
  "pub_date": "2024-01-15T10:30:00",
  "media_urls": ["https://instagram.com/..."],
  "scraped_at": "2024-01-20T15:30:00.000Z",
  "authorMeta": {
    "username": "photographer",
    "full_name": "John Photographer",
    "profile_url": "https://www.instagram.com/photographer/",
    "is_verified": false
  }
}
```

### Cookie Authentication

#### Option 1: MongoDB Cookie Rotation (Automatic)

The scraper automatically connects to MongoDB for cookie rotation. This provides:

- Round-robin cookie selection
- Automatic failover when cookies fail
- Usage tracking and failure detection
- Email alerts for cookie failures

#### Option 2: Manual Cookie Input

Export cookies from your browser and provide them in the `cookies` parameter:

1. Install a browser extension like "Cookie-Editor" or "EditThisCookie"
2. Log into Instagram in your browser
3. Export cookies as JSON
4. Paste the JSON into the `cookies` input parameter

#### Option 3: File-Based Cookies

Place a cookies file in the scraper directory:

- `www.instagram.com.cookies (1).json`
- `www.instagram.com.cookies.json`
- `cookies.json`
- `IG_Cookies.json`

### Anti-Blocking Measures

This scraper includes multiple anti-detection features:

1. **Stealth Scripts**: Override navigator properties to avoid bot detection
2. **Human Behavior Simulation**: Random mouse movements, scrolling, and delays
3. **Cookie Rotation**: Automatic rotation through multiple accounts
4. **Random Delays**: Variable delays between requests
5. **Firefox Browser**: Uses Firefox which has better anti-detection properties

### Error Handling

The scraper handles various error scenarios:

- **Profile Not Found**: Returns error message if profile doesn't exist
- **Private Account**: Tagged posts are not accessible for private accounts
- **No Tagged Posts**: Returns message if user has no tagged posts
- **Rate Limiting**: Automatically stops if Instagram blocks access
- **Cookie Failure**: Rotates to next cookie and sends email alert

### Limitations

- Tagged posts are only visible if the target profile is public
- Instagram may limit access without authentication
- Rate limits apply - avoid scraping too many posts too quickly
- Some posts may be restricted based on account settings

### Local Development

```bash
## Install dependencies
pip install -r requirements.txt

## Install Playwright browsers
playwright install firefox

## Run locally
apify run
```

### Deployment to Apify

```bash
## Login to Apify
apify login

## Push to Apify
apify push
```

### Support

If you encounter issues:

1. Ensure cookies are valid and not expired
2. Check if the target profile is public
3. Reduce `maxPosts` to avoid rate limiting

# Actor input Schema

## `usernames` (type: `array`):

One or more Instagram usernames whose tagged posts to scrape (with or without @ symbol). Each username is processed separately - the results for one username start being scraped in the background as soon as its post URLs are found, while the next username's tagged tab is being crawled.

## `maxPosts` (type: `integer`):

Maximum number of tagged posts to extract for each username.

## `cookies` (type: `string`):

Instagram authentication cookies in JSON format. OPTIONAL - if not provided, MongoDB cookie rotation or default cookies will be used. For better results, export cookies from your browser after logging into Instagram.

## `sessionName` (type: `string`):

Name for saving/loading cookies between runs. Use different names for different Instagram accounts.

## Actor input object example

```json
{
  "usernames": [
    "instagram",
    "natgeo"
  ],
  "maxPosts": 50,
  "cookies": "[{\"name\":\"sessionid\",\"value\":\"your_session_id\",\"domain\":\".instagram.com\",\"path\":\"/\",\"secure\":true,\"httpOnly\":true}]",
  "sessionName": "my_instagram_session"
}
```

# Actor output Schema

## `posts` (type: `string`):

No description

# 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 = {
    "usernames": [
        "instagram"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("crawlerbros/instagram-tagged-posts-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 = { "usernames": ["instagram"] }

# Run the Actor and wait for it to finish
run = client.actor("crawlerbros/instagram-tagged-posts-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 '{
  "usernames": [
    "instagram"
  ]
}' |
apify call crawlerbros/instagram-tagged-posts-scraper --silent --output-dataset

```

## MCP server setup

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

```

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/0eA4sXizWzZaEKSSR/builds/9j8AsbQeywa0Anfr9/openapi.json
