# Instagram Scraper (`lukaku/instagram-scraper`) Actor

- **URL**: https://apify.com/lukaku/instagram-scraper.md
- **Developed by:** [Khánh Chung](https://apify.com/lukaku) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 0 monthly users, 100.0% runs succeeded, 0 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

## Instagram URL Scraper

An Apify Actor that classifies each Instagram URL and routes it to a dedicated extractor. It captures Instagram JSON responses and embedded page data, then emits normalized records for public media, profiles, comments, stories, highlights, hashtags, locations, audio pages, guides and explore feeds.

### Supported URLs

| URL | Default output | Compatible `resultsType` |
| --- | --- | --- |
| `/p/<shortcode>/` | Post/image/video/carousel detail | `details`, `comments` |
| `/reel/<shortcode>/`, `/reels/<shortcode>/` | Reel detail | `details`, `comments` |
| `/<user>/reel/<shortcode>/` | Reel detail | `details`, `comments` |
| `/tv/<shortcode>/` | Legacy IGTV/video detail | `details`, `comments` |
| `/p/<shortcode>/c/<comment-id>/` | One comment | `comments` |
| `/share/<token>/`, `/share/p/<token>/`, `/share/reel/<token>/` | Resolved target | `details`, `comments` |
| `/<username>/` or `/<numeric-profile-id>/` | Profile detail | `details`, `posts`, `reels`, `tagged`, `stories`, `highlights` |
| `/<username>/posts/` | Profile posts | `posts` |
| `/<username>/reels/` | Profile reels | `reels` |
| `/<username>/tagged/` | Tagged media | `tagged` |
| `/<username>/highlights/` | Highlight media | `highlights` |
| `/stories/<username>/[<story-id>/]` | Active story media | `stories` |
| `/stories/highlights/<highlight-id>/` | Highlight media | `highlights` |
| `/s/<encoded-highlight>/?story_media_id=...` | Shared highlight/story | `highlights` |
| `/explore/tags/<tag>/` | Hashtag details | `details`, `posts`, `reels` |
| `/explore/locations/<id>/<slug>/` | Location details | `details`, `posts`, `reels` |
| `/reels/audio/<audio-id>/` | Audio details | `details`, `reels` |
| `/<username>/guide/<slug>/<id>/` | Legacy guide content | `posts` |
| `/explore/` or `/explore/search/?q=...` | Explore media | `posts`, `reels` |

`/embed/` variants and tracking query parameters are accepted. Non-content paths such as `/accounts/`, `/direct/` and `/settings/` are rejected instead of being mistaken for profiles.

### Input

```json
{
  "input": [
    { "url": "https://www.instagram.com/p/SHORTCODE/" },
    {
      "url": "https://www.instagram.com/natgeo/",
      "resultsType": "posts",
      "resultsLimit": 25
    },
    {
      "url": "https://www.instagram.com/p/SHORTCODE/",
      "resultsType": "comments",
      "resultsLimit": 100
    }
  ],
  "resultsType": "auto",
  "resultsLimit": 50,
  "onlyPostsNewerThan": "30 days",
  "includeRaw": false,
  "maxConcurrency": 3,
  "maxRequestRetries": 2,
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}
```

`resultsType` and `resultsLimit` can be set globally or overridden on an individual input object. An incompatible combination, such as `comments` for a profile URL, produces an `INVALID_RESULTS_TYPE` record before crawling while other valid inputs continue.

### Output model

Every row has these envelope fields:

```json
{
  "schemaVersion": 1,
  "type": "post",
  "status": "succeeded",
  "sourceUrl": "https://www.instagram.com/reel/SHORTCODE/",
  "url": "https://www.instagram.com/reel/SHORTCODE/",
  "scrapedAt": "2026-09-05T00:00:00.000Z"
}
```

Possible successful `type` values are `post`, `profile`, `comment`, `story`, `highlight`, `hashtag`, `location`, `audio`, and `guide`.

Posts use `contentType` to distinguish `image`, `video`, `carousel`, `reel`, and `igtv`. A carousel is one dataset record whose ordered children are in `media[]`.

For posts, `text` contains only the authored caption and `textSource` identifies where it was recovered (`caption`, `open_graph`, or `null`). Instagram generated accessibility description remains available only as `media[].accessibilityText`; it is never substituted for the authored caption.

Post records preserve the same base contract as the Threads scraper: `type`, `status`, `sourceUrl`, `url`, `id`, `shortcode`, `text`, `urls`, `metrics`, `author`, `postedAt`, `language`, and `media`. Instagram-specific fields are additive. The common metric keys are `likes`, `replies`, `reposts`, `quotes`, `shares`, and `views`; Instagram also exposes `comments` and `plays`. Unsupported or unavailable values are `null`.

`urls` contains unique outbound links recovered from caption text and structured CTA, ad, or link-sticker metadata. CDN media asset URLs remain in `media[]` and are excluded from `urls`.

Collection URLs emit one row per child item, up to `resultsLimit`. Every child includes `parent`, which identifies the profile, hashtag, location, audio, guide, highlight or explore URL that produced it.

Failures are explicit and do not silently become empty results:

```json
{
  "schemaVersion": 1,
  "type": "story",
  "status": "failed",
  "sourceUrl": "https://www.instagram.com/stories/example/",
  "url": "https://www.instagram.com/accounts/login/",
  "errorCode": "LOGIN_WALL",
  "error": "Instagram requires authentication for this content",
  "retryable": false,
  "scrapedAt": "2026-09-05T00:00:00.000Z"
}
```

Other stable failure codes include `INVALID_URL`, `NOT_FOUND`, `PRIVATE_CONTENT`, `RATE_LIMITED`, `EXTRACTION_FAILED`, `UNSUPPORTED_URL`, and `REQUEST_FAILED`.

### Extraction strategy

The Actor deliberately avoids relying on one hard-coded GraphQL document ID. For each page it:

1. Captures Instagram JSON network responses.
2. Parses JSON and `data-sjs` script payloads embedded in the page.
3. Scrolls collection surfaces conservatively to trigger pagination.
4. Scores media/profile/metadata candidates against identifiers from the input URL.
5. Uses Open Graph data as a reduced-quality fallback for direct public pages.
6. Normalizes private-API, GraphQL and page metadata shapes into the same public schema.

### Access limitations

The Actor does not bypass privacy controls. Instagram may require a logged-in session for stories, highlights, deep comments, hashtag feeds, followers, private accounts, or some regions/IP ranges. In those cases the Actor emits `LOGIN_WALL` or `PRIVATE_CONTENT`. Residential proxies and low concurrency improve reliability but do not make private content public.

CDN media URLs are often signed and can expire. Download or consume them soon after the run.

### Local development

```bash
npm install
npm test
apify run
```

Without the Apify CLI, place input in `storage/key_value_stores/default/INPUT.json` and run `npm start`.

### Deploy

```bash
npx apify-cli login
npx apify-cli push
```

# Actor input Schema

## `input` (type: `array`):

URLs as strings or request objects. A request object may override resultsType and resultsLimit.

## `resultsType` (type: `string`):

Auto uses the natural type of each URL. Other values request a compatible child collection, such as comments for a post or reels for a profile.

## `resultsLimit` (type: `integer`):

Maximum number of child items emitted for feeds, comments, stories, highlights and guides.

## `onlyPostsNewerThan` (type: `string`):

Optional ISO date/time or relative duration such as '7 days', '2 months' or '1 year'.

## `includeRaw` (type: `boolean`):

Include the selected raw Instagram object. This can make records much larger.

## `maxConcurrency` (type: `integer`):

Maximum browser pages processed at once. Conservative values reduce blocking.

## `maxRequestRetries` (type: `integer`):

How many times to retry a URL after a navigation or extraction failure.

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

Residential proxies are strongly recommended for Instagram.

## Actor input object example

```json
{
  "input": [
    {
      "url": "https://www.instagram.com/instagram/"
    },
    {
      "url": "https://www.instagram.com/reel/C5i1-I7sQ6d/"
    }
  ],
  "resultsType": "auto",
  "resultsLimit": 50,
  "includeRaw": false,
  "maxConcurrency": 3,
  "maxRequestRetries": 2,
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}
```

# Actor output Schema

## `results` (type: `string`):

Normalized Instagram content and failure records.

# 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 = {
    "input": [
        {
            "url": "https://www.instagram.com/instagram/"
        },
        {
            "url": "https://www.instagram.com/reel/C5i1-I7sQ6d/"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("lukaku/instagram-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 = { "input": [
        { "url": "https://www.instagram.com/instagram/" },
        { "url": "https://www.instagram.com/reel/C5i1-I7sQ6d/" },
    ] }

# Run the Actor and wait for it to finish
run = client.actor("lukaku/instagram-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 '{
  "input": [
    {
      "url": "https://www.instagram.com/instagram/"
    },
    {
      "url": "https://www.instagram.com/reel/C5i1-I7sQ6d/"
    }
  ]
}' |
apify call lukaku/instagram-scraper --silent --output-dataset

```

## MCP server setup

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