# Instagram Hashtag Scraper: Views, Likes & Date Filter (`ziyank/instagram-hashtag-scraper`) Actor

Scrape Instagram posts and reels by hashtag with views, likes and comments on every row. Filter by date (e.g. last 30 days), reels only, or minimum views/likes, and pull older posts from creators using the tag. No login or cookies. Get more with no duplicates.

- **URL**: https://apify.com/ziyank/instagram-hashtag-scraper.md
- **Developed by:** [Ziyan Karmali](https://apify.com/ziyank) (community)
- **Features:** Limited permissions
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.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/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 Hashtag Scraper: Views, Likes & Date Filter

Scrape Instagram hashtag posts and reels with a **since/until date filter**, **view counts**, and optional **older-post backfill**. No login, no cookies, no account risk. You only pay for results.

### Why this one

| You asked for (in reviews of other scrapers) | This actor |
|---|---|
| "needs an as-of date option" | `postedAfter` / `postedBefore`: a date, an ISO timestamp, or `"30 days"`. Every row is checked; out-of-range posts are never fetched or charged. |
| "can you please add view count" | Views **and** likes **and** comments on the same row (`metricsComplete: true`), from hashtag pages and older-post backfill alike |
| "only scraped recent posts, not older ones" | `includeOlderPosts`: checks the latest posts of creators active in the hashtag and keeps the in-range ones that carry the exact hashtag |
| surprise bills / limits ignored | Hard `maxResultsPerHashtag` and `maxPagesPerHashtag` caps. Stops cleanly at your Apify spending limit, and a row is never pushed unless you can pay for it. |

### Input

```json
{
  "hashtags": ["streetwear", "#mumbaifood"],
  "postedAfter": "60 days",
  "postedBefore": "",
  "includeOlderPosts": true,
  "completeMetrics": true,
  "contentType": "all",
  "minViews": 0,
  "strictHashtag": true,
  "maxResultsPerHashtag": 20
}
```

Need more than 20? Run again with `"continueFromRunId": "<previous run ID>"` (the ID is in that run's OUTPUT as `continueWith`). You get the next batch; already-delivered posts are skipped and never charged twice.

Advanced options: `maxPagesPerHashtag` (40), `relatedTopics` (5), `relatedDepth` (1), `maxCreatorsPerHashtag` (10), `creatorMissLimit` (3), `maxConcurrency` (3), `proxy`.

### Output (one row per post/reel, 31 fields, always the same keys)

```json
{
  "id": "3774598606448511949",
  "shortCode": "DRiEW8TDEvN",
  "url": "https://www.instagram.com/reel/DRiEW8TDEvN/",
  "type": "Video",
  "timestamp": "2025-11-26T20:00:39.935Z",
  "timestampSource": "media_id",
  "caption": "fall fits>>>\n#streetwear #streetstyle #outfitinspiration",
  "hashtags": ["streetwear", "streetstyle", "outfitinspiration"],
  "videoPlayCount": 2011170,
  "likesCount": null,
  "commentsCount": null,
  "ownerUsername": "david.kxm",
  "inputHashtag": "streetwear",
  "matchType": "exact_hashtag",
  "discoveredVia": "popular_page"
}
```

- `timestampSource`: `taken_at` is exact. `media_id` is decoded from Instagram's media ID and is accurate to a few minutes (live check: 0 s to 3.4 min off, because the ID is minted when the upload starts).
- `discoveredVia`: `popular_page`, `related_topic:<topic>`, or `creator_profile:<username>`.
- `matchType`: `exact_hashtag` (caption contains the #tag), or `related_topic` when `strictHashtag` is off.

### How every row gets views + likes + comments

Instagram shows logged-out visitors different metrics on different pages, so the actor joins them per post:

| Where the post was found | Views from | Likes + comments from | Extra cost |
|---|---|---|---|
| Hashtag / related-topic page | the topic page | public **embed page**, one light HTTP request with no browser. If the creator disabled embeds, the full post page instead | included in the result price |
| Older-post backfill | creator's **Reels tab** (views + likes + comments for 12 reels in one page) | embed page (also gives the caption for the hashtag check) | per page checked |

- Live test (2026-12-02): 14/15 rows complete from embeds alone. The 15th was a creator with embeds disabled, now covered by the post-page fallback (verified on that post: 73,867 likes / 307 comments).
- Rows where the creator **hid** like/view counts come back with `countsHidden: true` and nulls. Nobody can get those logged out.
- Photos and carousels have no view count on Instagram; they're `metricsComplete` with likes + comments.
- Turn `completeMetrics` off for the fastest views-only run (no extra requests).

### Honest limits

- Instagram's full chronological hashtag feed needs a logged-in account. **We don't use accounts**, so this is a broad, date-filterable sample of a hashtag, not a complete archive.
- Backfill yield depends on how consistently creators use the tag: in live tests about 1 in 10 checked posts qualified. That's why it's opt-in, billed per page checked, and skips a creator after `creatorMissLimit` misses in a row.
- "Posts only" mostly returns results with backfill on, because hashtag pages are reel-heavy.

### Pricing (pay per event)

| Event | Price |
|---|---|
| Actor start | $0.005 |
| Result (row in dataset) | $0.002 ($2.00 / 1,000) |
| Older-post check (backfill page or caption check, opt-in) | $0.001 |

A default 20-result run costs about $0.045. Backfill adds $0.001 per check, bounded by your page and creator limits (e.g. about $0.05 for 13 older posts in a 60-day #mumbaifood run).

### How it works

`#tag` → `/popular/<tag>` (about 12 top items + related topics) → related topic pages, fetched in parallel → *(optional)* each creator's Reels tab + grid → their in-range posts.

- **No browser at all.** Every page is fetched as plain HTML (Instagram server-renders all the data we use), about 120 KB per page instead of about 1 MB, on a slim Node image that starts in seconds.
- **Cheap proxies first, residential as the safety net.** With the default proxy, each request first tries a datacenter IP. Anything that fails is retried on residential (which keeps its full retry budget), and datacenter is switched off for the run if it keeps failing. Results are identical; only the cost changes.
- **Parallel but exact.** Pages and lookups run concurrently, but rows are evaluated and saved in a fixed order under a lock, so `maxResultsPerHashtag` and your spending limit are never exceeded.
- **Dates before requests.** Post dates are decoded from media IDs, so out-of-range posts never cost a request.
- **Duplicates removed** across sources, hashtags and continued runs.
- Run diagnostics (requests, timings and fallbacks per page type) are in OUTPUT → `fetcher`.

#### Known gaps (logged-out limits)

- Reels pinned on a creator's Reels tab use up slots in the 12 reels Instagram shows logged-out visitors. A backfilled reel older than those slots gets likes and comments but no view count (`metricsComplete: false`). In a live test this affected 2 of 13 #mumbaifood rows.

### Development

```bash
npm install
npm test                 # 30 unit tests (ids, filters, input, normalize, engine)
apify run                # local run (needs Playwright browsers)
apify push               # deploy
```

Live test harness: `test/live/` (see TEST_REPORT.md).

# Actor input Schema

## `hashtags` (type: `array`):

One or more hashtags, with or without #. Each is scraped separately; duplicates across hashtags are removed.

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

Only posts newer than this. A date (2026-01-31), an ISO timestamp, or a relative window such as "30 days" or "6 months".

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

Only posts older than this. Same formats as "Posted after".

## `includeOlderPosts` (type: `boolean`):

Also checks the latest posts of creators who use the hashtag and keeps those inside your date range that carry the exact hashtag. Finds far more dated posts, at an extra per-result fee. This is a broad sample, not Instagram's complete hashtag archive.

## `completeMetrics` (type: `boolean`):

Fill in likes and comments for reels found on hashtag pages (which only show views) with one lightweight extra request per result. Included in the result price. Turn off for the fastest, views-only run.

## `contentType` (type: `string`):

Keep everything, only reels/videos, or only photo/carousel posts.

## `minViews` (type: `integer`):

Drop reels with fewer plays. Posts without a view count are dropped when this is above 0.

## `minLikes` (type: `integer`):

Drop posts with fewer likes. Needs "Complete metrics" on for reels found on hashtag pages.

## `strictHashtag` (type: `boolean`):

Keep only posts whose caption contains the exact #hashtag. Turn off to also get posts from Instagram's related topics (labelled matchType = related_topic).

## `maxResultsPerHashtag` (type: `integer`):

Results per hashtag in this run (default 20 keeps runs fast and cheap). Need more? Run again with "Continue from run" to get the next batch with no duplicates.

## `continueFromRunId` (type: `string`):

Paste the run ID of a previous run of this Actor (same hashtags) to get the next batch of results. Results already delivered are skipped and not charged again. The ID is shown in that run's OUTPUT as continueWith.

## `maxPagesPerHashtag` (type: `integer`):

Hard cap on pages visited per hashtag. Keeps run time and cost predictable.

## `relatedTopics` (type: `integer`):

How many of Instagram's related topic pages to explore per hashtag. Each adds up to ~12 posts. 0 = only the hashtag's own page.

## `relatedDepth` (type: `integer`):

How many hops of related topics to follow. 1 = only topics linked from the hashtag page.

## `maxCreatorsPerHashtag` (type: `integer`):

During older-post backfill, how many creators who used the hashtag to check.

## `creatorMissLimit` (type: `integer`):

During backfill, stop checking a creator after this many posts in a row without the hashtag. Saves page loads (and your money) on creators who rarely use it.

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

How many hashtags to scrape at the same time.

## `datacenterFirst` (type: `boolean`):

With the default residential proxy, each request first tries a cheaper datacenter IP; anything that fails is retried on residential, and datacenter is switched off for the run if it keeps failing. Results are identical either way. Ignored when you set your own proxy.

## `proxy` (type: `object`):

Proxy settings. Residential proxies are recommended for Instagram.

## Actor input object example

```json
{
  "hashtags": [
    "streetwear"
  ],
  "includeOlderPosts": false,
  "completeMetrics": true,
  "contentType": "all",
  "minViews": 0,
  "minLikes": 0,
  "strictHashtag": true,
  "maxResultsPerHashtag": 20,
  "maxPagesPerHashtag": 40,
  "relatedTopics": 5,
  "relatedDepth": 1,
  "maxCreatorsPerHashtag": 10,
  "creatorMissLimit": 3,
  "maxConcurrency": 3,
  "datacenterFirst": true,
  "proxy": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  }
}
```

# Actor output Schema

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

One row per post/reel: URL, posted time, creator, views, likes, comments, caption, hashtags.

## `summary` (type: `string`):

Per-hashtag counts, why each hashtag stopped, request diagnostics, and continueWith (the continueFromRunId to fetch the next batch).

# 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 = {
    "hashtags": [
        "streetwear"
    ],
    "maxResultsPerHashtag": 20
};

// Run the Actor and wait for it to finish
const run = await client.actor("ziyank/instagram-hashtag-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 = {
    "hashtags": ["streetwear"],
    "maxResultsPerHashtag": 20,
}

# Run the Actor and wait for it to finish
run = client.actor("ziyank/instagram-hashtag-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 '{
  "hashtags": [
    "streetwear"
  ],
  "maxResultsPerHashtag": 20
}' |
apify call ziyank/instagram-hashtag-scraper --silent --output-dataset

```

## MCP server setup

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