# Instagram Profile & Post Scraper (`moving_beacon-owner1/my-actor-34`) Actor

A Python-based Instagram profile scraper that accepts a username or profile URL and extracts public profile details along with complete post information. The tool normalizes and outputs clean, post-level data ready for analysis, CSV/JSON export, or Apify dataset integration.

- **URL**: https://apify.com/moving\_beacon-owner1/my-actor-34.md
- **Developed by:** [Jamshaid Arif](https://apify.com/moving_beacon-owner1) (community)
- **Categories:** Social media, Developer tools
- **Stats:** 3 total users, 0 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $10.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/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 Profile Scraper

This project scrapes **public Instagram profiles** using a **username or profile URL** and extracts **complete post-level information** in a structured format.

The scraper is designed for **data analysis, research, and automation pipelines** and outputs clean, flattened data ready for storage or further processing.

***

### ✨ Features

- Scrape Instagram profiles using:

  - ✅ Username (e.g. `jamshaid_ds`)
  - ✅ Profile URL (e.g. `https://www.instagram.com/jamshaid_ds`)
- Extract **profile-level data**
- Extract **all available post information**
- Automatically normalize nested data
- Export results as:

  - CSV
  - JSON
  - Apify Dataset (Actor.push\_data)

***

### 📌 Extracted Profile Information

For each Instagram profile:

- `username`
- `full_name`
- `avatar_url`
- `bio`
- `website`
- `followers`
- `following`
- `posts_count`
- `is_private`

***

### 📸 Extracted Post Information

For **each post**:

- `image_url`
- `caption`
- `download_link`
- `posted_at`
- `post_type` (image / video / reel)

Each row in the final dataset represents **one post**.

***

### 🛠️ Tech Stack

- Python 3.10+
- Pandas
- Async scraping
- Apify Actor SDK (optional)
- CSV / JSON data handling

***

### 🚀 Usage

#### 1️⃣ Install Dependencies

```bash
pip install -r requirements.txt
```

***

#### 2️⃣ Provide Input

You can pass either:

- **Username**

```text
jamshaid_ds
```

- **Profile URL**

```text
https://www.instagram.com/jamshaid_ds/
```

The scraper automatically extracts the username from the URL if needed.

***

#### 3️⃣ Run the Scraper

```bash
python main.py
```

***

### 📤 Output Format

#### CSV Output

```csv
username,full_name,followers,following,image_url,caption,posted_at,post_type
```

#### JSON / Apify Dataset Output

```json
{
  "username": "@jamshaid_ds",
  "full_name": "Jamshaid Arif",
  "image_url": "https://...",
  "caption": "CSLB SCRAPER...",
  "posted_at": "2025-10-22 08:07:48",
  "post_type": "image"
}
```

***

### 🔄 Data Normalization Logic

- `posts_data` is converted from string → dictionary
- Nested post data is flattened using `pandas.json_normalize`
- Final dataset is **post-level**, not profile-level

This ensures compatibility with:

- Databases (PostgreSQL, MySQL)
- Analytics pipelines
- Apify datasets

***

### 📦 Apify Integration (Optional)

If running as an Apify Actor:

```python
await Actor.push_data(df_final.to_dict(orient="records"))
```

Each post is pushed as a separate dataset item.

***

### ⚠️ Limitations

- Only **public profiles** are supported
- Private accounts cannot be scraped
- Instagram rate limits may apply
- This tool does not bypass authentication

***

### 📄 Disclaimer

This project is for **educational and research purposes only**.
Users are responsible for complying with Instagram’s Terms of Service and applicable laws.

***

# Actor input Schema

## `search` (type: `string`):

The keyword to search for (e.g., 'lawyers in Rawalpindi')

## `max_scrolls` (type: `integer`):

The maximum number of Scrolls to scrape

## Actor input object example

```json
{
  "search": "Real Estate in New York",
  "max_scrolls": 30
}
```

# Actor output Schema

## `overview` (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 = {
    "search": "Real Estate in New York"
};

// Run the Actor and wait for it to finish
const run = await client.actor("moving_beacon-owner1/my-actor-34").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 = { "search": "Real Estate in New York" }

# Run the Actor and wait for it to finish
run = client.actor("moving_beacon-owner1/my-actor-34").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 '{
  "search": "Real Estate in New York"
}' |
apify call moving_beacon-owner1/my-actor-34 --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=moving_beacon-owner1/my-actor-34",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/OrhloLv56qhrEmVe7/builds/Sg6YLFHcKMCiln0Qf/openapi.json
