# Instagram Search Scraper (`filexy634/instagram-search-scraper`) Actor

Search Instagram posts like the in-app search bar and scrape matching users, hashtags and places, optionally including each hashtag's posts.

- **URL**: https://apify.com/filexy634/instagram-search-scraper.md
- **Developed by:** [code gerald](https://apify.com/filexy634) (community)
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 71.4% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $4.00 / 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?

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 Search Scraper

Search Instagram exactly like the in-app search bar and get structured results back: matching **accounts**, **hashtags**, **places**, and **posts** - plus, optionally, the posts under every matched hashtag.

### What you get

Type in a search term the way you would in the Instagram app (e.g. `travel`, `nasa`, `coffee shop`) and this Actor returns:

- **Accounts** that match the term, with username, full name, profile picture, verified/private status
- **Hashtags** that match the term, with post counts
- **Places** that match the term, with address and coordinates
- **Posts** matched directly by keyword (the same results you'd see on the "Top" tab), with caption, media, likes, and comments
- Optionally, the actual posts under every matched hashtag

### Before you run it

This Actor needs a logged-in Instagram session to search (the same way you need to be logged in to use the search bar on instagram.com). If the Actor doesn't already have one configured, you'll need to supply your own in the `sessionCookie` input field:

1. Use a secondary/throwaway Instagram account - not your main one. Automated searching can get an account temporarily restricted.
2. Log in to instagram.com in a desktop browser.
3. Open DevTools (F12) → **Network** tab, reload the page, click any request to `www.instagram.com`, and find the **Cookie** request header.
4. Copy the **entire** value (it looks like `sessionid=...; csrftoken=...; ds_user_id=...; mid=...; ig_did=...; ...`) - not just the `sessionid` part, the search features need the full cookie to work reliably.
5. Paste that whole string into the `sessionCookie` input field.

Cookies expire or get invalidated if you log out elsewhere, so grab a fresh one if runs start failing with a session error.

### Input

| Field | Description | Default |
|---|---|---|
| `searchQueries` | List of terms to search, one per entry | - (required) |
| `searchTypes` | Which result types to include: `users`, `hashtags`, `places`, `posts` | all four |
| `resultsLimitPerQuery` | Max matches kept per query, per type (1-100) | 20 |
| `includeHashtagPosts` | Also scrape the posts under every matched hashtag | off |
| `postsPerHashtag` | Max posts per hashtag when the above is on (1-1000) | 30 |
| `postedAfter` / `postedBefore` | Keep only posts/reels published within this date range. Instagram's search has no native date filter, so this is applied client-side to post results only (accounts/hashtags/places are unaffected) | - |
| `sessionCookie` | Your Instagram cookie string (see above), if not already configured | - |
| `proxyConfiguration` | Proxy settings; residential proxies recommended | Apify residential proxy |

### Output

Results are stored in the default dataset, one item per row. The `resultType` field tells you what kind of row it is:

**`user`**

```json
{ "resultType": "user", "query": "nasa", "name": "nasa", "fullName": "NASA", "url": "https://www.instagram.com/nasa/", "isVerified": true, "isPrivate": false }
```

**`hashtag`**

```json
{ "resultType": "hashtag", "query": "travel", "name": "travel", "mediaCount": 650000000, "url": "https://www.instagram.com/explore/tags/travel/" }
```

**`place`**

```json
{ "resultType": "place", "query": "paris", "name": "Paris, France", "address": "...", "lat": 48.8566, "lng": 2.3522, "url": "..." }
```

**`post`** (from `posts` search type or `includeHashtagPosts`)

```json
{
  "resultType": "post",
  "query": "travel",
  "shortCode": "Cx...",
  "caption": "Chasing sunsets in Santorini 🌅 #travel #greece",
  "hashtagsInCaption": ["travel", "greece"],
  "mentionsInCaption": [],
  "ownerUsername": "someuser",
  "ownerFullName": "Some User",
  "ownerIsVerified": false,
  "likesCount": 1234,
  "commentsCount": 56,
  "viewsCount": null,
  "locationName": "Santorini, Greece",
  "isSponsored": false,
  "displayUrl": "...",
  "videoUrl": null
}
```

Posts also include `timestamp`, `ownerId`, `ownerProfilePicUrl`, `isVideo`, `mediaType`, `productType`, `videoDuration`, `width`, `height`, `accessibilityCaption`, `isCommentsDisabled`, and `locationId`.

If a query returns nothing on any of the selected tabs, you'll get an item with `error` and `errorDescription` instead, so you can tell a genuine empty result apart from a failed one.

### Tips

- Keep your query list and volumes moderate - aggressive automated searching is what gets accounts rate-limited or restricted by Instagram.
- Usernames and hashtags never contain spaces or punctuation, so a query like `econet 5g` automatically retries as `econet5g` if the first attempt finds nothing.
- If one result type (say, places) fails for a query, the others still come through - check the run log to see exactly which tab failed and why.
- Instagram occasionally changes its internal response formats; if results suddenly stop appearing, that's usually the first sign and worth reporting.
- Only public data is collected. Respect Instagram's Terms of Service and applicable data-protection laws when using the results.

# Actor input Schema

## `searchQueries` (type: `array`):

Terms to type into Instagram's search bar, e.g. "travel" or "nasa". De-duplicated.

## `searchTypes` (type: `array`):

Which kinds of search-bar matches to keep for each query. "posts" are actual posts/reels matched by keyword (the "Top" tab), independent of any hashtag.

## `resultsLimitPerQuery` (type: `integer`):

Maximum number of search-bar matches kept per query (across the selected types).

## `includeHashtagPosts` (type: `boolean`):

For every matched hashtag, also scrape its top/recent posts.

## `postsPerHashtag` (type: `integer`):

Maximum number of posts scraped per matched hashtag, when "Include hashtag posts" is on.

## `postedAfter` (type: `string`):

Only keep posts/reels published on or after this date. Instagram's search itself has no date filter, so this is applied client-side to post results (accounts/hashtags/places aren't affected). Leave blank for no lower bound.

## `postedBefore` (type: `string`):

Only keep posts/reels published on or before this date. Same client-side filtering caveat as "Posted after". Leave blank for no upper bound.

## `sessionCookie` (type: `string`):

Full cookie string copied from a logged-in browser request to www.instagram.com (e.g. "sessionid=...; csrftoken=...; ds_user_id=...; mid=...; ig_did=..."). A bare sessionid is often not enough for search. Only used if the Actor owner has not configured the IG_SESSION_COOKIE secret env var.

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

Residential proxies are recommended. Set the proxy country to where the Instagram account normally logs in.

## Actor input object example

```json
{
  "searchTypes": [
    "users",
    "hashtags",
    "places",
    "posts"
  ],
  "resultsLimitPerQuery": 20,
  "includeHashtagPosts": false,
  "postsPerHashtag": 30,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  }
}
```

# Actor output Schema

## `overview` (type: `string`):

Table view of the scraped results.

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

Full dataset items, including error items for queries that could not be searched.

# 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 = {
    "proxyConfiguration": {
        "useApifyProxy": true,
        "apifyProxyGroups": [
            "RESIDENTIAL"
        ]
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("filexy634/instagram-search-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 = { "proxyConfiguration": {
        "useApifyProxy": True,
        "apifyProxyGroups": ["RESIDENTIAL"],
    } }

# Run the Actor and wait for it to finish
run = client.actor("filexy634/instagram-search-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 '{
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  }
}' |
apify call filexy634/instagram-search-scraper --silent --output-dataset

```

## MCP server setup

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