parser

package module
v0.0.0-...-715778e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 10 Imported by: 0

README

instagram-auto

instagram parser for w_popularity.

Status

Best-effort public-HTML scrape implemented. A camoufox CDP skeleton is wired but not yet active.

Production caveat: Instagram aggressively blocks logged-out HTTP scraping. Public profiles currently still leak follower / following / posts counts in the og:description meta tag, but Instagram changes this often. For reliable operation you should run this parser behind camoufox + a valid session cookie — the public path here is a fallback, not a primary.

Strategy

  1. Primary (public HTML). GET https://www.instagram.com/<handle>/ with a realistic browser UA. Parse the og:description (and name=description) meta for the canonical "<n> Followers, <n> Following, <n> Posts - …" pattern. Supports K/M/B suffixes and thousands-separated integers.
  2. Fallback (camoufox). When the public path returns an auth wall, the parser routes the request through camoufox via CDP. The skeleton is in place (Config.CamoufoxURL, fetchViaCamoufox); real CDP wiring is a TODO.
Error mapping
Condition Returned error
200 OK but no counts meta shared.ErrAuth
HTML redirect to /accounts/login shared.ErrAuth
HTTP 404 shared.ErrNotFound
HTTP 429 shared.ErrRateLimited

FetchRecentPosts returns (nil, nil) on the logged-out path — Instagram blocks media listings for guests.

Usage

import parser "github.com/suenot/instagram-auto"

p := parser.New(parser.Config{
    HTTPTimeout: 15 * time.Second,
    CamoufoxURL: os.Getenv("CAMOUFOX_URL"), // optional fallback
})
snap, err := p.FetchChannel(ctx, handle)

License

MIT

Documentation

Overview

Package parser implements the w_popularity instagram adapter.

Strategy:

primary:  best-effort public HTML scrape — Instagram serves a meta
          description like "46 Followers, 226 Following, 7 Posts - …"
          on public profiles, even without cookies. We regex those
          three numbers out of the og:description / description meta.
fallback: camoufox via CDP (skeleton only — not yet wired). In
          production Instagram aggressively blocks logged-out HTTP
          scraping; the realistic primary path is camoufox + cookies.

FetchRecentPosts returns (nil, nil) on the logged-out path because Instagram blocks media listings for guests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// HTTPTimeout caps every outbound call. Defaults to 15s.
	HTTPTimeout time.Duration
	// UserAgent overrides the default UA string used for HTML requests.
	UserAgent string
	// CamoufoxURL is the CDP endpoint of a running camoufox instance
	// (e.g. "http://camoufox:3000"). When empty, the camoufox fallback
	// is disabled and ErrAuth is returned for logged-out walls.
	CamoufoxURL string
	// HTTPClient overrides the default *http.Client. Mainly useful in tests
	// for routing requests to an httptest.Server.
	HTTPClient *http.Client
	// BaseURL overrides https://www.instagram.com. Test hook.
	BaseURL string
}

Config controls runtime behaviour.

type InstagramParser

type InstagramParser struct {
	// contains filtered or unexported fields
}

InstagramParser is the shared.Parser implementation for Instagram.

func New

func New(cfg Config) *InstagramParser

New constructs an Instagram parser.

func (*InstagramParser) FetchChannel

func (p *InstagramParser) FetchChannel(ctx context.Context, handle string) (shared.ChannelSnapshot, error)

FetchChannel attempts the public-HTML primary path, then falls back to the camoufox skeleton if configured.

func (*InstagramParser) FetchRecentPosts

func (p *InstagramParser) FetchRecentPosts(ctx context.Context, handle string, since time.Time) ([]shared.PostSnapshot, error)

FetchRecentPosts returns (nil, nil) for the logged-out path — Instagram blocks media listings for guests.

func (*InstagramParser) Platform

func (p *InstagramParser) Platform() shared.Platform

Platform returns shared.PlatformInstagram.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL