Skip to main content

instagram-graphql-scraper

Collects posts from a public Instagram profile by capturing the browser's profile GraphQL request, then replaying subsequent pages through one requests.Session.

Installation

pip install -r requirements.txt
# or
pip install -e .

Usage

from instagram_graphql_scraper import InstagramGraphqlScraper

scraper = InstagramGraphqlScraper(driver_path="/path/to/chromedriver")
try:
    posts = scraper.get_user_posts("username", max_pages=2, max_posts=24)
finally:
    scraper.close()

The browser flow opens the profile, dismisses an optional login dialog, scrolls once, clears Selenium Wire requests, and clicks the dynamic show-more-posts button once. The captured request supplies the URL, headers, cookies, form payload, variables, and doc_id; no dynamic GraphQL values are hardcoded.

days_limit keeps posts newer than N days and stops pagination early once older posts are reached, using each post's accessibility_caption date; posts without a parseable date are kept. Combine with max_pages or max_posts for additional bounds.

For bounded asynchronous Embed enrichment (opt-in, not run automatically by get_user_posts):

import asyncio
from instagram_graphql_scraper import InstagramEmbedClient

async def enrich(posts):
    async with InstagramEmbedClient(max_concurrency=10) as client:
        return await client.fetch_many(posts)

details = asyncio.run(enrich(posts))

The batch client preserves input order, deduplicates shortcodes per run, and returns a per-post error result instead of failing the whole batch. The single-post normalized CLI remains available:

python3 instagram_context_json.py "https://www.instagram.com/p/SHORTCODE/embed/captioned/"
python3 instagram_context_json.py "https://www.instagram.com/p/SHORTCODE/embed/captioned/" --full

Tests

python3 -m pytest -q

The manual browser check is intentionally not part of CI:

python3 manual_integration.py 1989ivyshao --driver-path /path/to/chromedriver --max-pages 2

Documentation

See docs/ for the system architecture diagram, class diagram, and a bilingual (繁體中文 / English) SRE testing runbook covering environment setup, parameter boundaries, and known issues.

Do not place cookies, CSRF/LSD tokens, or captured payloads in source, fixtures, or logs.

License

MIT, see LICENSE.

Metadata

Release files for instagram-graphql-scraper 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for instagram-graphql-scraper 0.1.0
File Size Uploaded
instagram_graphql_scraper-0.1.0.tar.gz 25.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for instagram-graphql-scraper 0.1.0
File Interpreter ABI Platform
instagram_graphql_scraper-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 50.4 kB

Release files / instagram_graphql_scraper-0.1.0.tar.gz

Download URL instagram_graphql_scraper-0.1.0.tar.gz
Size 25.6 kB
Tags Source
SHA-256 checksum
How to use checksums
547f3da9dbe0c8fb22b3f2dd5104b0a135332771f5b1d3cf9a368da6d796a66d
BLAKE2b-256 checksum
How to use checksums
11ebd53d5056e11f95fbdc268c284a2a3e4c810d4656698b063447f5d3d8aa07
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.13.1

Release files / instagram_graphql_scraper-0.1.0-py3-none-any.whl

Download URL instagram_graphql_scraper-0.1.0-py3-none-any.whl
Size 24.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ecbf364663feedf47d0f4493e9b5b475aee8106272caf595a3255e4034b8b13d
BLAKE2b-256 checksum
How to use checksums
b6c8d6279bd55b9eddb7e417b20d937ba877bb425f7effe51a682a9adcc87c12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.13.1

Release history Release notifications | RSS feed

0.2.1

2 release files

0.2.0

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page