Skip to content

feat(instagram): anonymous Instagram scraper across REST, agent, and MCP surfaces#1593

Merged
MODSetter merged 73 commits into
MODSetter:devfrom
AnishSarkar22:feat/instagram-scraper
Jul 11, 2026
Merged

feat(instagram): anonymous Instagram scraper across REST, agent, and MCP surfaces#1593
MODSetter merged 73 commits into
MODSetter:devfrom
AnishSarkar22:feat/instagram-scraper

Conversation

@AnishSarkar22

@AnishSarkar22 AnishSarkar22 commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Description

  • Adds a platform-native, anonymous-only Instagram scraper that stays on the cheap HTTP tier (app.utils.proxy + scrapling), no browser and no login/sessionid ever; its input/output mirrors the public Instagram actor spec (resultsType/directUrls/camelCase, additive extra="allow" parity) so existing callers work unchanged.
  • Warms an anonymous session (csrftoken + mid + x-ig-app-id) on a sticky-IP proxy, then rotates the IP and re-warms on login walls (401/403), backs off on 429, returns None on 404, and raises InstagramAccessBlockedError on an /accounts/login/ redirect instead of a silent empty.
  • Supports three flows: profile details via web_profile_info JSON, profile feed posts/reels via parse_media, and single post/reel extraction that reads the embedded mobile-v1 PolarisMedia JSON with Open Graph meta as a lossy fallback (parse_post); numeric-ID post URLs are skipped since the page keys on the shortcode.
  • Adds Google-backed profile discovery (site:instagram.com <query> via the existing google_search platform) because Instagram's native keyword search is login-walled; keeps only profile hits, de-dupes, and caps at searchLimit.
  • Deliberately drops hashtag feeds, place feeds, comment threads, and IG native search — all 302 to login for logged-out callers; comment content stays login-walled and only the comment count (commentsCount) is exposed.
  • Emits rich fields beyond the core set: carousel children (images/childPosts), tagged users, coauthor producers, location, product type, pin state, and related profiles.
  • Wires a capability layer (app/capabilities/instagram/) with scrape and details verbs (definitions, executors, schemas) exposing REST endpoints, plus per-returned-item billing.
  • Adds an Instagram chat subagent (agent, description, system prompt, tools) with registry/constants wiring, and an MCP server scraper tool with selfcheck + server registration.
  • Fans targets out on an 8-way warm-session pool, de-dupes media by id, and applies resultsLimit / onlyPostsNewerThan as request-time policy.
  • Updates the web app: connector docs and index/meta, marketing content, playground catalog, platform icon/SVG, and homepage hero/use-case sections; adds Instagram to public route prefixes in auth-utils.
  • Adds offline unit tests (schema/URL resolver, parsers incl. relay + og shapes, Google discovery, fetch resilience/fan-out, budget caps, capability executor/registry/schemas) and a live stress/accuracy harness (scripts/stress/stress_instagram_scraper.py) with discovery, single-post probe, mentions-wall probe, and field-coverage modes.
  • Documents known limits: likesCount is best-effort (often withheld anonymously), deep feed pagination is out of scope for v1, and the $3.50/1k items meter should be re-measured before high-volume use.

Motivation and Context

FIX #

Screenshots

API Changes

  • This PR includes API changes

Change Type

  • Bug fix
  • New feature
  • Performance improvement
  • Refactoring
  • Documentation
  • Dependency/Build system
  • Breaking change
  • Other (specify):

Testing Performed

  • Tested locally
  • Manual/QA verification

Checklist

  • Follows project coding standards and conventions
  • Documentation updated as needed
  • Dependencies updated as needed
  • No lint/build errors or new warnings
  • All relevant tests are passing

High-level PR Summary

This PR introduces a complete anonymous Instagram scraper platform integration across the entire SurfSense stack. The implementation adds the ability to scrape public Instagram posts, reels, and profile details without authentication, using a proxy-based anonymous approach similar to the existing Reddit scraper. The feature includes a proprietary scraping layer (app/proprietary/platforms/instagram), two capability verbs (instagram.scrape and instagram.details), an AI agent subagent for multi-agent chat, MCP server tools, comprehensive unit tests, an e2e testing script, billing integration with per-item metering, and full marketing/documentation pages on the web frontend.

⏱️ Estimated Review Time: 3+ hours

💡 Review Order Suggestion
Order File Path
1 surfsense_backend/app/proprietary/platforms/instagram/README.md
2 surfsense_backend/app/proprietary/platforms/instagram/__init__.py
3 surfsense_backend/app/proprietary/platforms/instagram/schemas.py
4 surfsense_backend/app/proprietary/platforms/instagram/url_resolver.py
5 surfsense_backend/app/proprietary/platforms/instagram/parsers.py
6 surfsense_backend/app/proprietary/platforms/instagram/fetch.py
7 surfsense_backend/app/proprietary/platforms/instagram/scraper.py
8 surfsense_backend/app/capabilities/instagram/__init__.py
9 surfsense_backend/app/capabilities/instagram/scrape/schemas.py
10 surfsense_backend/app/capabilities/instagram/scrape/executor.py
11 surfsense_backend/app/capabilities/instagram/scrape/definition.py
12 surfsense_backend/app/capabilities/instagram/details/schemas.py
13 surfsense_backend/app/capabilities/instagram/details/executor.py
14 surfsense_backend/app/capabilities/instagram/details/definition.py
15 surfsense_backend/app/capabilities/core/billing.py
16 surfsense_backend/app/capabilities/core/types.py
17 surfsense_backend/app/config/__init__.py
18 surfsense_backend/.env.example
19 surfsense_backend/app/agents/chat/multi_agent_chat/subagents/builtins/instagram/agent.py
20 surfsense_backend/app/agents/chat/multi_agent_chat/subagents/builtins/instagram/description.md
21 surfsense_backend/app/agents/chat/multi_agent_chat/subagents/builtins/instagram/system_prompt.md
22 surfsense_backend/app/agents/chat/multi_agent_chat/subagents/builtins/instagram/tools/index.py
23 surfsense_backend/app/agents/chat/multi_agent_chat/subagents/registry.py
24 surfsense_backend/app/agents/chat/multi_agent_chat/constants.py
25 surfsense_backend/app/routes/__init__.py
26 surfsense_backend/tests/unit/platforms/instagram/test_skeleton.py
27 surfsense_backend/tests/unit/platforms/instagram/test_parsers.py
28 surfsense_backend/tests/unit/platforms/instagram/test_discovery.py
29 surfsense_backend/tests/unit/platforms/instagram/test_fetch_resilience.py
30 surfsense_backend/tests/unit/platforms/instagram/test_budget.py
31 surfsense_backend/tests/unit/capabilities/instagram/test_executor.py
32 surfsense_backend/tests/unit/capabilities/instagram/test_registry.py
33 surfsense_backend/tests/unit/capabilities/instagram/test_schemas.py
34 surfsense_backend/tests/unit/capabilities/test_billing.py
35 surfsense_backend/scripts/e2e_instagram_scraper.py
36 surfsense_mcp/mcp_server/features/scrapers/platforms/instagram.py
37 surfsense_mcp/mcp_server/features/scrapers/__init__.py
38 surfsense_mcp/mcp_server/selfcheck.py
39 surfsense_mcp/mcp_server/server.py
40 surfsense_web/lib/connectors-marketing/instagram.tsx
41 surfsense_web/lib/connectors-marketing/index.ts
42 surfsense_web/lib/playground/catalog.ts
43 surfsense_web/lib/playground/platform-icons.tsx
44 surfsense_web/content/docs/connectors/native/instagram.mdx
45 surfsense_web/content/docs/connectors/native/meta.json
46 surfsense_web/app/(home)/mcp-server/page.tsx
47 surfsense_web/components/homepage/hero-section.tsx
48 surfsense_web/components/homepage/use-cases.tsx
49 surfsense_web/content/docs/how-to/mcp-server.mdx
50 surfsense_backend/.gitignore
51 surfsense_backend/tests/unit/agents/multi_agent_chat/test_subagent_composition.py
52 surfsense_web/lib/auth-utils.ts
53 surfsense_web/lib/connectors-marketing/google-maps.tsx
54 surfsense_web/lib/connectors-marketing/google-search.tsx
55 surfsense_web/lib/connectors-marketing/reddit.tsx
56 surfsense_web/lib/connectors-marketing/web-crawl.tsx
57 surfsense_web/lib/connectors-marketing/youtube.tsx
58 surfsense_web/content/docs/connectors/index.mdx
59 surfsense_web/content/docs/connectors/native/index.mdx
60 surfsense_web/public/connectors/instagram.svg

Need help? Join our Discord

Added detection for Instagram's soft login wall, which returns a 200 status with login HTML. Implemented a new function to identify login redirects and adjusted the fetch logic to treat these cases similarly to 401/403 responses.
Added tests to handle scenarios where a 200 status response is redirected to a login page, ensuring proper rotation of IPs and raising errors when persistent login redirects occur. Updated the _FakeSession class to support login wall detection.
- Added support for extracting likes, comments, username, timestamp, and caption from Open Graph meta tags.
- Implemented fallback mechanisms to ensure graceful degradation when expected data is missing.
- Updated unit tests to validate new parsing logic and ensure robustness against unrecognized formats.
- Enhanced the regular expression for mentions to prevent trailing punctuation from being included in handles.
- Added support for extracting media IDs from deep-link meta tags in anonymous posts.
- Updated unit tests to validate the new media ID extraction and ensure proper handling of mentions.
@vercel

vercel Bot commented Jul 10, 2026

Copy link
Copy Markdown

@AnishSarkar22 is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 418f4b1a-0eb9-4d42-ab1a-b33b7fc17c65

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@AnishSarkar22 AnishSarkar22 changed the title Feat/instagram scraper feat(instagram): anonymous Instagram scraper across REST, agent, and MCP surfaces Jul 10, 2026
…ng TikTok scraping capabilities, including comments, user search, and trending features. Updated README and documentation to reflect the addition of 24 native tools.
@MODSetter MODSetter merged commit b341b0a into MODSetter:dev Jul 11, 2026
3 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants